Geert Roumen
Published © CC BY

From Pixel to NeoPixel

Use the cursor to change the colour of NeoPixels. Create light experiences using visual software like Photoshop or After Effects.

AdvancedFull instructions provided6,759

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
Any Arduino compatible board would work
×1
Adafruit NeoPixel Digital RGB LED Strip 144 LED, 1m White
Adafruit NeoPixel Digital RGB LED Strip 144 LED, 1m White
Any Neopixel (https://www.adafruit.com/category/168) or WS2812B or SK6812-based LEDs would work
×1
USB-A to B Cable
USB-A to B Cable
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
This is needed when you get Neopixels without wires or pins pre-solderedn on them

Story

Read more

Schematics

Arduino with Single Neopixel

Arduino UNO with a single Neopixel connected to port 10

Arduino with Neopixel ring

Arduino with Neopixel ring 24 pixels, connected to pin 10. Make sure to update the NUMPIXELS in the Arduino code

Code

FromPixelToNeopixel_ProcessingCode

Processing
This code sends the current color of the pixel that is 'selected' by the cursor over to the Arduino that can transfer it to neopixels or other hardware.
/*
@Title Processing to Arduino RGB LED (Neopixels)
@Author Geert Roumen
@Institute Umeå Institute of Design
@Date 29-01-2018
 
@Software
IDE:  Processing 3.3.6
OS:   Windows 10.0.17134 Build 17134
*/
 
import java.awt.*;
Robot robot;
import processing.serial.*;
 
Serial myPort;  
int val;       
 
//Setup the communication and Robot instance
//See https://docs.oracle.com/javase/7/docs/api/java/awt/Robot.html#getPixelColor(int,%20int)
 
void setup(){
  size(1000, 150);
  //Connect to the first Serial port of the PC
  String portName = Serial.list()[0];
  print("Serial ports: ");
  println(Serial.list());
  print("Chose ");
  print(portName);
  //Try to open this port
  myPort = new Serial(this, portName, 9600);
  //If you want this window to always stay on top
  //surface.setAlwaysOnTop(true);
 
  //Try to create a AWT Robot
  try
  {
    robot = new Robot();
 
  }catch (AWTException e){
    throw new RuntimeException("Unable to Initialize", e);
  }
 
}
//Make a counter variable
int i=0;
 
void draw(){
  //Get the location of the pointer (mouse/cursor)
  Point mouse;
  mouse = MouseInfo.getPointerInfo().getLocation();
 
  //Get the color at the location of the pointer, pointer icon is ignored
  Color c = robot.getPixelColor(mouse.x,mouse.y);
 
  //Get the integer RGB value at this point
  int top = c.getRGB();
 
  //Write an S to the Serial port
  myPort.write('S'); 
 
  //Do some conversion to make it look white when all colors are 255
  //These values are based on neopixels.
  float r = (float) (red(top)*0.780);//(199/255));
  float g = (float) (green(top)*0.99);//;(254/255));
  float b = (float) (blue(top)*0.56);//(144/255));
 
  //Start writing the [RGB] as three bytes 
  myPort.write((byte) r); 
  myPort.write((byte) g); 
  myPort.write((byte)b);  
  i++;
  stroke(top);
  line(i,0,i+1,150);
}
int j=0;
//if a key is pressed an image of the current 'flow' will be saved.
void keyPressed() {
  j++;
  save("image"+j+".tif");
  background(0);
  i=0;
}

FromPixelToNeopixel_ArduinoCode

Arduino
This code is recieving RGB values from processing and passing it on to the neopixel LED strip.
/*
@Title Processing to Arduino RGB LED (Neopixels)
@Author Geert Roumen
@Institute Umeå Institute of Design
@Date 29-01-2018
 
@Hardware
 
Arduino   RGB Neopixel
 
GND       GND
10        Input
5V/USB    Power
 
Arduino
 
https://arduino.cc
 
Neopixel:
https://www.adafruit.com/category/168
 
In this example sketch Processing can send an RGB value to Arduino and Arduino will change the LED color of the NUMPIXELS connected neopixels
*/
 
#include <Adafruit_NeoPixel.h>
 
//
#define PIN            10
 
//The amount of pixels connected to the Arduino, make sure they are powered correctly
#define NUMPIXELS      24
 
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
 
void setup() {
  Serial.begin(9600);
  pixels.begin(); // This initializes the NeoPixel library.
}
 
void loop() {
 
  // For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one.
  int r;
  int g;
  int b;
  if(Serial.available()) {   
    if(Serial.read() == 'S') {
      //When it finds an 'S' char, it will wait untill it finds 3 other bytes
      while(!Serial.available()){}
      r = Serial.read();
      while(!Serial.available()){}
      g = Serial.read();
      while(!Serial.available()){}
      b = Serial.read();
    }
    delay(10); // some recovery time, not sure if nessecary
 
    for(int i=0;i<NUMPIXELS;i++){
 
    // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
    pixels.setPixelColor(i, pixels.Color(r,g,b)); // Moderately bright green color.
 
  }
      pixels.show(); // This sends the updated pixel color to the hardware
  }
 
}

Credits

Geert Roumen

Geert Roumen

6 projects • 10 followers
I’m a maker and interaction designer, bridging the digital and physical world. and make prototypes and do research in a playful way.

Comments