-
Notifications
You must be signed in to change notification settings - Fork 9
/
AdalightFastled.ino
56 lines (42 loc) · 1.21 KB
/
AdalightFastled.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <FastLED.h>
#define NUM_LEDS 156
#define DATA_PIN 2
#define SERIALRATE 500000
#define CALIBRATION_TEMPERATURE TypicalLEDStrip // Color correction
#define MAX_BRIGHTNESS 255 // 0-255
// 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;
CRGB leds[NUM_LEDS];
void setup()
{
FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
FastLED.setTemperature( CALIBRATION_TEMPERATURE );
FastLED.setBrightness( MAX_BRIGHTNESS );
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());
if (prefix[i] == Serial.read()) continue;
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;
}
Serial.readBytes((char*)leds, NUM_LEDS*3);
// shows new values
FastLED.show();
}