#include "LPD8806.h" #include "SPI.h" // Example to control LPD8806-based RGB LED Modules in a strip /*****************************************************************************/ // Number of RGB LEDs in strand: int nLEDs = 32; // Chose 2 pins for output; can be any valid output pins: int dataPin = 2; int clockPin = 3; // First parameter is the number of LEDs in the strand. The LED strips // are 32 LEDs per meter but you can extend or cut the strip. Next two // parameters are SPI data and clock pins: LPD8806 strip = LPD8806(32, dataPin, clockPin); // You can optionally use hardware SPI for faster writes, just leave out // the data and clock pin parameters. But this does limit use to very // specific pins on the Arduino. For "classic" Arduinos (Uno, Duemilanove, // etc.), data = pin 11, clock = pin 13. For Arduino Mega, data = pin 51, // clock = pin 52. For 32u4 Breakout Board+ and Teensy, data = pin B2, // clock = pin B1. For Leonardo, this can ONLY be done on the ICSP pins. //LPD8806 strip = LPD8806(nLEDs); void setup() { // Start up the LED strip strip.begin(); // Update the strip, to start they are all 'off' strip.show(); } void loop() { // Send a simple pixel chase in... colorChase(strip.Color(127, 127, 127), 50); // White colorChase(strip.Color(127, 0, 0), 50); // Red colorChase(strip.Color(127, 127, 0), 50); // Yellow colorChase(strip.Color( 0, 127, 0), 50); // Green colorChase(strip.Color( 0, 127, 127), 50); // Cyan colorChase(strip.Color( 0, 0, 127), 50); // Blue colorChase(strip.Color(127, 0, 127), 50); // Violet // Fill the entire strip with... colorWipe(strip.Color(127, 0, 0), 50); // Red colorWipe(strip.Color( 0, 127, 0), 50); // Green colorWipe(strip.Color( 0, 0, 127), 50); // Blue rainbow(10); rainbowCycle(0); // make it go through the cycle fairly fast } void rainbow(uint8_t wait) { int i, j; for (j=0; j < 384; j++) { // 3 cycles of all 384 colors in the wheel for (i=0; i < strip.numPixels(); i++) { strip.setPixelColor(i, Wheel( (i + j) % 384)); } strip.show(); // write all the pixels out delay(wait); } } // Slightly different, this one makes the rainbow wheel equally distributed // along the chain void rainbowCycle(uint8_t wait) { uint16_t i, j; for (j=0; j < 384 * 5; j++) { // 5 cycles of all 384 colors in the wheel for (i=0; i < strip.numPixels(); i++) { // tricky math! we use each pixel as a fraction of the full 384-color wheel // (thats the i / strip.numPixels() part) // Then add in j which makes the colors go around per pixel // the % 384 is to make the wheel cycle around strip.setPixelColor(i, Wheel( ((i * 384 / strip.numPixels()) + j) % 384) ); } strip.show(); // write all the pixels out delay(wait); } } // Fill the dots progressively along the strip. void colorWipe(uint32_t c, uint8_t wait) { int i; for (i=0; i < strip.numPixels(); i++) { strip.setPixelColor(i, c); strip.show(); delay(wait); } } // Chase one dot down the full strip. void colorChase(uint32_t c, uint8_t wait) { int i; // Start by turning all pixels off: for(i=0; i