Skip to content

Instantly share code, notes, and snippets.

@jrsconfitto
Created February 8, 2013 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrsconfitto/4739005 to your computer and use it in GitHub Desktop.
Save jrsconfitto/4739005 to your computer and use it in GitHub Desktop.
// Using adafruit's LED library: https://github.com/adafruit/LPD8806
#include <LPD8806.h>
#include <SPI.h>
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);
int incomingByte = 0; // for incoming serial data
void colorChase(uint32_t c, uint8_t wait);
void setup() {
// Start up the LED strip
strip.begin();
// Update the strip, to start they are all 'off'
strip.show();
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}
void loop() {
// send data only when you receive data:
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
// say what you got:
Serial.print("I received: ");
Serial.println(incomingByte, DEC);
}
else {
incomingByte = 2;
}
Serial.println("Looping the lights");
// Send a simple pixel chase based on the sent time
colorChase(strip.Color(127,127,127), incomingByte - '0'); // white
colorChase(strip.Color(127,0,0) , incomingByte - '0'); // red
colorChase(strip.Color(127,127,0) , incomingByte - '0'); // yellow
colorChase(strip.Color(0,127,0) , incomingByte - '0'); // green
colorChase(strip.Color(0,127,127) , incomingByte - '0'); // cyan
colorChase(strip.Color(0,0,127) , incomingByte - '0'); // blue
colorChase(strip.Color(127,0,127) , incomingByte - '0'); // magenta
}
// Chase a dot down the strip
// good for testing purposes
void colorChase(uint32_t c, uint8_t wait) {
int i;
Serial.print("Wait time is: ");
Serial.println(wait, DEC);
for (i=0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, 0); // turn all pixels off
}
for (i=0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, c); // set one pixel
strip.show(); // refresh strip display
delay(wait); // hold image for a moment
strip.setPixelColor(i, 0); // erase pixel (but don't refresh yet)
}
strip.show(); // for last erased pixel
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment