-
Notifications
You must be signed in to change notification settings - Fork 2
/
Test_1
117 lines (101 loc) · 4.28 KB
/
Test_1
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include "FastLED.h"
// How many leds in your strip?
#define NUM_LEDS 240
// For led chips like Neopixels, which have a data line, ground, and power, you just
// need to define DATA_PIN. For led chipsets that are SPI based (four wires - data, clock,
// ground, and power), like the LPD8806 define both DATA_PIN and CLOCK_PIN
#define DATA_PIN 16
#define CLOCK_PIN 15
#define COLOR_ORDER RGB
// 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;
// Baudrate, higher rate allows faster refresh rate and more LEDs (defined in .conf file)
#define serialRate 460800
// Define the array of leds
CRGB leds[NUM_LEDS];
void setup() {
// Uncomment/edit one of the following lines for your leds arrangement.
// FastLED.addLeds<NEOPIXEL , DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<BTM1829 , DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<TM1812 , DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<TM1809 , DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<TM1804 , DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<TM1803 , DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<UCS1903 , DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<UCS1903B , DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<UCS1904 , DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<UCS2903 , DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<WS2812 , DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<WS2852 , DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<WS2812B , DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<SK6812 , DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<SK6822 , DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<APA106 , DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<PL9823 , DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<WS2811 , DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<WS2813 , DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<APA104 , DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<WS2811_40 , DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<GW6205 , DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<GW6205_40 , DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<LPD1886 , DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<LPD1886_8BIT, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<LPD8806, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
FastLED.addLeds<WS2801 , DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<WS2803 , DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<SM16716, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<P9813 , DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<APA102 , DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<SK9822 , DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<DOTSTAR, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
// initial RGB flash
LEDS.showColor(CRGB(255, 0, 0));
delay(250);
LEDS.showColor(CRGB(0, 255, 0));
delay(250);
LEDS.showColor(CRGB(0, 0, 255));
delay(250);
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();
leds[i].r = r;
leds[i].g = g;
leds[i].b = b;
}
// shows new values
FastLED.show();
}