Controlling NeoPixels

A NeoPixel is a smart RGB LED. They can be linked together into long chains or grids, and programmed easily with only 1 wire from the Arduino. It is controlled by sending an 8 bit integer for Red, Green and Blue to the Pixel. This is most easily achieved through use of the NeoPixel library you were asked to install.

The test units I provided have only a single NeoPixel. This makes them a bit less interesting since they are normally used in groups, but they can still do 24 bit color, so the exercise is still at least a little fun.

Here is a simple sketch to use it. Note that the Wheel() function isn't used in the example, but it could be useful in your own script:

#include <Adafruit_NeoPixel.h>

#define PIN 6

// Initialize a strip with a single pixel
Adafruit_NeoPixel strip = Adafruit_NeoPixel(1, PIN, NEO_GRB + NEO_KHZ800);

int lval=0;

void setup() {
  strip.begin();            // startup the strip
  strip.setPixelColor(0,strip.Color(0,64,96));   // purple
  strip.show();             // Initialize pixel to set color
}

void loop() {
delay(50);     // this isn't really necessary
}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  if(WheelPos < 85) {
   return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } else if(WheelPos < 170) {
   WheelPos -= 85;
   return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } else {
   WheelPos -= 170;
   return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
}

You're done. There is nothing to turn in. If there is time, and you like, you are welcome to do one of the other exercises. Otherwise you're done!

LectureVideo/ArduinoLab/NeoPixel (last edited 2015-02-23 04:12:35 by SteveLudtke)