-
Notifications
You must be signed in to change notification settings - Fork 1
/
rgb_led_firmware.ino
83 lines (65 loc) · 1.79 KB
/
rgb_led_firmware.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <NeoPixelBus.h>
#undef SERIAL_RX_BUFFER_SIZE
#define SERIAL_RX_BUFFER_SIZE 512 // incrase size of serial buffer
const uint16_t BAUDRATE = 9600;
const uint16_t LED_COUNT = 60;
const uint8_t LED_PIN = 13; // make sure to set this to the correct pin
const uint8_t COLOR_SATURATION = 128;
NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(LED_COUNT, LED_PIN);
RgbColor red(COLOR_SATURATION, 0, 0);
RgbColor green(0, COLOR_SATURATION, 0);
RgbColor blue(0, 0, COLOR_SATURATION);
RgbColor white(COLOR_SATURATION);
RgbColor startColor(15,60,10);
// LRGB - led, red, green, blue
// led means index of led,
// led can store special values:
// 255 - applay changes,
// 254 - set R,G,B color to all leds
uint8_t LRGB[4];
uint16_t counter=0;
void setup()
{
delay(2000); //give PC some time to bootup in case of restart
Serial.begin(BAUDRATE);
while (!Serial); // wait for serial attach
// this resets all the neopixels to an off state
strip.Begin();
strip.Show();
for(int i=0; i<LED_COUNT; ++i)
{
strip.SetPixelColor(i, startColor);
}
strip.Show();
}
void setAllLedsToColor(const uint8_t R, const uint8_t G, const uint8_t B)
{
RgbColor color(R,G,B);
for(uint8_t i = 0; i < LED_COUNT; ++i)
{
strip.SetPixelColor(i, color);
}
}
void loop()
{
if (Serial.available() > 0)
{
LRGB[counter] = Serial.read();
counter++;
if(counter>3)
{
counter=0;
switch(LRGB[0]) {
case 255://show changes
strip.Show();
break;
case 254://set all leds to one color
setAllLedsToColor(LRGB[1],LRGB[2],LRGB[3]);
break;
default:
RgbColor color(LRGB[1],LRGB[2],LRGB[3]);
strip.SetPixelColor(LRGB[0], color);
}
}
}
}