-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLEDControllerSource.ino
More file actions
337 lines (292 loc) · 7.24 KB
/
LEDControllerSource.ino
File metadata and controls
337 lines (292 loc) · 7.24 KB
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
/*Includes*/
#include "FastLED.h"
/*LED Settings*/
#define NUM_LEDS 10 // Number of LEDs (Or LED controller chips on strip)
#define DATA_PIN 9 // Pin which the data cable is connected.
#define MAX_BRIGHTNESS 255 // Max Brightness (Default 255)
#define LED_CHIPSET TM1803 // LED Chipset.
#define COLOR_ORDER GBR // Color order (RGB, RBG, BGR, BRG, GRB, GBR) See FastLED examples (RGB Calibration) for finding correct order.
//DEMO_MODE mode includes many flashing features and random colors, turning this off loops a gentle rainbow effect for at home use.
#define DEMO_MODE true
//Not currently functional. (Future feature will react to currently playing music, may require additional hardware).
#define MUSIC_MODE false
// This is only used for debugging functions and testing other stuff.
#define DEBUG_MODE false
//Global Variables.
CRGB leds[NUM_LEDS];
uint32_t g_color;
long n;
/*MANDATORY FUNCTIONS*/
// Create the LED object
/*setup() is called by the Arduino on powerup or reboot.*/
void setup()
{
FastLED.addLeds<LED_CHIPSET, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS);
}
// Main function loop.
/*loop() is called by arduino after setup() and after loop().*/
void loop()
{
if (DEBUG_MODE){
//n = randomFunction();
//prntInColorInt(n);
rColorTest();
}else{
if (DEMO_MODE){
randFunction();
}else{
rainbow(5);
}
}
}
/*UTILITY FUNCTIONS*/
uint32_t createRGB(uint8_t r, uint8_t g, uint8_t b)
{
return ((r & 0xff) << 16) + ((g & 0xff) << 8) + (b & 0xff);
}
void rseed(){
randomSeed(millis());
delay(10);
}
uint16_t random255(){
rseed();
long r = random(10,256);
return r;
}
uint32_t randomColor(){
uint8_t r_R= random255();
uint8_t g_G = random255();
uint8_t b_B = random255();
return createRGB(r_R, g_G, b_B);
}
long randomFunction(){
rseed();
long r = random(0,6);
return r;
}
uint32_t randomRGB(){
rseed();
long r = random(0,3);
uint32_t c;
if (r == 0){
c = CRGB::Red;
}else{
if (r == 1){
c = CRGB::Green;
}else{
if (r == 2){
c = CRGB::Blue;
}else{
c = CRGB::White;
}
}
}
return c;
}
void randFunction(){
long e = randomFunction();
switch(e){
case 0:
cyln();
break;
case 1:
chase();
break;
case 2:
rMissing_chase();
break;
case 3:
//wave(5);
rWave(5);
break;
case 4:
//chase_slow();
rChase_slow();
break;
case 5:
default:
rainbow(5);
break;
}
}
/*MAIN LED EFFECTS*/
void color_chase(uint32_t color, uint8_t wait)
{
FastLED.clear();
FastLED.setBrightness(MAX_BRIGHTNESS);
for(int led_number = 0; led_number < NUM_LEDS; led_number++)
{
leds[led_number] = color;
FastLED.show();
delay(wait);
leds[led_number] = CRGB::Black;
}
return;
}
void missing_dot_chase(uint32_t color, uint8_t wait)
{
for (int led_brightness = MAX_BRIGHTNESS; led_brightness > 10; led_brightness/=2)
{
FastLED.setBrightness(led_brightness);
fill_solid(leds, NUM_LEDS, color);
for(int led_number = 0; led_number < NUM_LEDS; led_number++)
{
leds[led_number] = CRGB::Black;
if( led_number > 0 && led_number < NUM_LEDS)
{
leds[led_number-1] = color;
}
FastLED.show();
delay(wait);
}
}
return;
}
void missing_dot_chase_reverse(uint32_t color, uint8_t wait)
{
for (int led_brightness = 10; led_brightness < MAX_BRIGHTNESS; led_brightness*=2)
{
FastLED.setBrightness(led_brightness);
fill_solid(leds, NUM_LEDS, color);
for(int led_number = 0; led_number < NUM_LEDS; led_number++)
{
leds[led_number] = CRGB::Black;
if( led_number > 0 && led_number < NUM_LEDS)
{
leds[led_number-1] = color;
}
FastLED.show();
delay(wait);
}
}
return;
}
void cylon(CRGB color, uint16_t wait, uint8_t number_of_cycles)
{
FastLED.setBrightness(255);
for (uint8_t times = 0; times<=number_of_cycles; times++)
{
for(int led_number = 0; led_number < NUM_LEDS; led_number++)
{
leds[led_number] = color;
FastLED.show();
leds[led_number] = CRGB::Black;
delay(wait);
}
for(int led_number = NUM_LEDS-1; led_number >= 0; led_number--)
{
leds[led_number] = color;
FastLED.show();
leds[led_number] = CRGB::Black;
delay(wait);
}
}
return;
}
void rainbow(uint8_t wait)
{
uint16_t hue;
FastLED.clear();
FastLED.setBrightness(MAX_BRIGHTNESS);
for(hue=10; hue<255*3; hue++)
{
fill_rainbow( &(leds[0]), NUM_LEDS, hue);
FastLED.show();
delay(wait);
}
return;
}
/*DEBUG FUNCTIONS*/
void prntInColorInt(uint8_t i){
if (i == 0){
missing_dot_chase(CRGB::Red, 5);
}else{
for (uint8_t j = 1; j <= i; j++){
missing_dot_chase(0xcc00cc, 5);
delay(100);
}
}
delay(5000);
}
void colorTest(){
uint32_t c = randomRGB();
missing_dot_chase(c, 5);
delay(1000);
}
void rColorTest(){
uint8_t r_R = random255();
rseed();
uint8_t g_G = random255();
rseed();
uint8_t b_B = random255();
//prntInColorInt(r_R);
uint32_t clor = createRGB( r_R, g_G, b_B);
missing_dot_chase(clor, 5);
delay(1000);
}
/*Function Modes*/
void cyln(){
g_color = randomColor();
cylon(g_color,25, 5);
}
void missing_chase(){
missing_dot_chase(CRGB::White, 20);
missing_dot_chase(CRGB::Red, 20);
missing_dot_chase(CRGB::Yellow, 20);
missing_dot_chase(CRGB::Green, 20);
missing_dot_chase(CRGB::Cyan, 20);
missing_dot_chase(CRGB::Blue, 20);
missing_dot_chase(0x3000cc, 20) ;
}
void chase(){
color_chase(CRGB::Green, 15);
color_chase(CRGB::BlueViolet, 15);
color_chase(CRGB::Red, 15);
color_chase(CRGB::Yellow, 15);
color_chase(CRGB::Green, 15);
color_chase(CRGB::Cyan, 15);
color_chase(CRGB::Blue, 15);
}
void chase_slow(){
color_chase(CRGB::White, 150);
color_chase(CRGB::Green, 150);
color_chase(CRGB::BlueViolet, 150);
color_chase(CRGB::Red, 150);
color_chase(CRGB::Yellow, 150);
color_chase(CRGB::Green, 150);
color_chase(CRGB::Cyan, 150);
color_chase(CRGB::Blue, 150);
}
void wave(uint8_t wait){
missing_dot_chase(CRGB::White, wait);
missing_dot_chase_reverse(CRGB::Red, wait);
missing_dot_chase(CRGB::Yellow, wait);
missing_dot_chase_reverse(CRGB::Green, wait);
missing_dot_chase(CRGB::Cyan, wait);
missing_dot_chase_reverse(CRGB::Blue, wait);
missing_dot_chase(0x3000cc, wait) ;
missing_dot_chase_reverse(CRGB::White, wait);
missing_dot_chase(CRGB::Red, wait);
missing_dot_chase_reverse(CRGB::Yellow, wait);
missing_dot_chase(CRGB::Green, wait);
missing_dot_chase_reverse(CRGB::Cyan, wait);
missing_dot_chase(CRGB::Blue, wait);
missing_dot_chase_reverse(0x3000cc, wait) ;
}
/*Random Simplified Function Modes*/
void rMissing_chase(){
for (uint8_t i=0;i<10;i++){
missing_dot_chase(randomColor(), 20);
}
}
void rWave(uint8_t wait){
for (uint8_t i=0;i<10;i++){
missing_dot_chase(randomColor(), wait);
missing_dot_chase_reverse(randomColor(), wait);
}
}
void rChase_slow(){
for (uint8_t i=0;i<10;i++){
color_chase(randomColor(), 150);
}
}