Want more features on Pastebin? Sign Up, it's FREE!
Guest

Simple Arduino Boblight Sketch for FastSPI

By: a guest on Jan 18th, 2013  |  syntax: C++  |  size: 1.33 KB  |  views: 172  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <FastSPI_LED.h>
  2.  
  3. #define stripLength 64 // Number of LEDs in your strip
  4.  
  5. // specified under `rate` in the `[device]` section of /etc/boblight.conf
  6. #define serialRate 115200
  7.  
  8. // boblightd sends a prefix (defined in /etc/boblight.conf) before sending the pixel data
  9. uint8_t prefix[] = {0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA};
  10.  
  11. struct CRGB { unsigned char g; unsigned char r; unsigned char b; };
  12. struct CRGB *leds;
  13.  
  14. #define PIN 8
  15.  
  16. void setup()
  17. {
  18.   FastSPI_LED.setLeds(stripLength);
  19.   FastSPI_LED.setChipset(CFastSPI_LED::SPI_TM1809);
  20.   FastSPI_LED.setPin(PIN);
  21.   FastSPI_LED.init();
  22.   FastSPI_LED.start();
  23.   Serial.begin(serialRate);
  24. }
  25.  
  26. void loop() {
  27. // wait until we see the prefix
  28.   for(byte i = 0; i < sizeof prefix; ++i) {
  29.     waitLoop: while (!Serial.available()) ;;
  30.     // look for the next byte in the sequence if we see the one we want
  31.     if(prefix[i] == Serial.read()) continue;
  32.     // otherwise, start over
  33.     i = 0;
  34.     goto waitLoop;
  35.   }
  36.   // read the transmitted data
  37.   for (uint8_t i = 0; i < stripLength; i++) {
  38.     byte r, g, b;
  39.     while(!Serial.available());
  40.     r = Serial.read();
  41.     while(!Serial.available());
  42.     g = Serial.read();
  43.     while(!Serial.available());
  44.     b = Serial.read();
  45.     leds[i].r = r;
  46.     leds[i].g = g;
  47.     leds[i].b = b;
  48.   }
  49.   FastSPI_LED.show();
  50. }
clone this paste RAW Paste Data