-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2020-LEDController.ino
60 lines (50 loc) · 987 Bytes
/
2020-LEDController.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
57
58
59
60
#include <FastLED.h>
#define LED_PIN 3
#define LED_COUNT 38
#define LOOP_DELAY 50 //50Hz
CRGB leds[LED_COUNT];
byte packet[256];
int availableBytes;
long i;
CRGB color;
void setup() {
Serial.begin(9600);
FastLED.addLeds<WS2812, LED_PIN, RGB>(leds, LED_COUNT);
}
void loop() {
int availableBytes = Serial.available();
if (availableBytes > 0) {
Serial.readBytes(packet, availableBytes);
Serial.println("Thing");
switch (packet[0]) {
case 0x00:
eraseAll();
break;
case 0x01:
pushLED();
break;
case 0x02:
overwriteLEDs();
break;
case 0x03:
break;
}
pushLED();
}
FastLED.show();
}
void eraseAll() {
color = CRGB(0, 0, 0);
for (i = 0; i < LED_COUNT; i++) {
leds[i] = color;
}
}
void pushLED() {
for (i = LED_COUNT - 1; i > 0; i--) {
leds[i] = leds[i - 1];
}
color = CRGB(packet[1], packet[2], packet[3]);
leds[i] = color;
}
void overwriteLEDs() {
}