Created
January 26, 2016 18:48
-
-
Save derpeter/f15abdb91441a0b2762c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Uses Adalight protocol and is compatible with Boblight, Prismatik etc | |
// "Magic Word" for synchronisation is 'Ada' followed by LED High, Low and Checksum | |
// source http://thai-fighter.blogspot.de/2014/05/arduino-adalight-clone-with-any-led.html | |
// | |
#include <FastLED.h> | |
///// User definitions ///// | |
// Define the number of LED Controllers | |
#define NUM_LEDS 30 | |
// Define SPI Pin | |
#define DATA_PIN 11 | |
// Baudrate, higher rate allows faster refresh rate and more LEDs (defined in /etc/boblight.conf) | |
#define serialRate 115200 | |
// Adalight sends a "Magic Word" (defined in /etc/boblight.conf) before sending the pixel data | |
uint8_t prefix[] = {'A', 'd', 'a'}, hi, lo, chk, i; | |
// initialise LED-array | |
CRGB leds[NUM_LEDS]; | |
void setup() | |
{ | |
// Uncomment one of the following lines for your leds arrangement. | |
// FastLED.addLeds<TM1803, DATA_PIN, RGB>(leds, NUM_LEDS); | |
// FastLED.addLeds<TM1804, DATA_PIN, RGB>(leds, NUM_LEDS); | |
// FastLED.addLeds<TM1809, DATA_PIN, RGB>(leds, NUM_LEDS); | |
// FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, NUM_LEDS); | |
// FastLED.addLeds<WS2812, DATA_PIN, RGB>(leds, NUM_LEDS); | |
// FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS); | |
// FastLED.addLeds<UCS1903, DATA_PIN, RGB>(leds, NUM_LEDS); | |
// FastLED.addLeds<WS2801, RGB>(leds, NUM_LEDS); | |
// FastLED.addLeds<SM16716, RGB>(leds, NUM_LEDS); | |
// FastLED.addLeds<LPD8806, RGB>(leds, NUM_LEDS); | |
// FastLED.addLeds<WS2801, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS); | |
// FastLED.addLeds<SM16716, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS); | |
// FastLED.addLeds<LPD8806, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS); | |
// initial RGB flash | |
LEDS.showColor(CRGB(255, 0, 0)); | |
delay(500); | |
LEDS.showColor(CRGB(0, 255, 0)); | |
delay(500); | |
LEDS.showColor(CRGB(0, 0, 255)); | |
delay(500); | |
LEDS.showColor(CRGB(0, 0, 0)); | |
Serial.begin(serialRate); | |
Serial.print("Ada\n"); // Send "Magic Word" string to host | |
} | |
void loop() { | |
// wait for first byte of Magic Word | |
for(i = 0; i < sizeof prefix; ++i) { | |
waitLoop: while (!Serial.available()) ;; | |
// Check next byte in Magic Word | |
if(prefix[i] == Serial.read()) continue; | |
// otherwise, start over | |
i = 0; | |
goto waitLoop; | |
} | |
// Hi, Lo, Checksum | |
while (!Serial.available()) ;; | |
hi=Serial.read(); | |
while (!Serial.available()) ;; | |
lo=Serial.read(); | |
while (!Serial.available()) ;; | |
chk=Serial.read(); | |
// if checksum does not match go back to wait | |
if (chk != (hi ^ lo ^ 0x55)) | |
{ | |
i=0; | |
goto waitLoop; | |
} | |
memset(leds, 0, NUM_LEDS * sizeof(struct CRGB)); | |
// read the transmission data and set LED values | |
for (uint8_t i = 0; i < NUM_LEDS; i++) { | |
byte r, g, b; | |
while(!Serial.available()); | |
r = Serial.read(); | |
while(!Serial.available()); | |
g = Serial.read(); | |
while(!Serial.available()); | |
b = Serial.read(); | |
//Change Variables to match output if strand is mismatched or try changing order of rgb in controller definition at top | |
leds[i].r = r; | |
leds[i].g = g; | |
leds[i].b = b; | |
} | |
// shows new values | |
FastLED.show(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment