-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLED-controller.ino
More file actions
249 lines (218 loc) · 5.49 KB
/
Copy pathLED-controller.ino
File metadata and controls
249 lines (218 loc) · 5.49 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
#include <BluetoothSerial.h>
#include <Adafruit_NeoPixel.h>
//adjust the following values to fit your setup:
//the length of your ws2812b strips in pixels:
#define LED_COUNT 300
//the arduino pin the LEDS are connected to:
#define led_pin 27
//the length of the animated strips
#define effect_length 10
//adjust the above values to fit your setup
/*
commands:
01: set mode
02: speed up
03: slow down
05: set brightness
*/
/*
modes:
0 - off
1 - rainbow 1
2 - rainbow 2
3 - bouncing strip
4 - christmas lights
5 - strobe light
6 - fire brigade lights
7 - portal
8 - police lights
9 - knight rider
10 - warm white
*/
int tempo[] = {0, 20, 20, 30, 600, 40, 50, 30, 400, 30, 3000};
int tempoincrement[] = {0, 3, 3, 3, 50, 3, 5, 3, 50, 3, 0};
int last = LED_COUNT - 1;
int length = effect_length - 1;
int mode, lasttime, timepassed, pixel;
float increment = 65536 / LED_COUNT;
float position, brightness;
bool direction;
uint16_t color;
uint32_t colorbuf;
BluetoothSerial Bluetooth;
Adafruit_NeoPixel strip(LED_COUNT, led_pin, NEO_GRB + NEO_KHZ800);
void setup() {
Bluetooth.begin("LED-Controller");
lasttime = millis();
strip.begin();
}
void loop() {
checkbluetooth();
checktime();
}
void checkbluetooth() {
if(Bluetooth.available()){
switch(Bluetooth.read()){
case 1: //new mode
mode = Bluetooth.read();
runAnimation();
break;
case 2: //speed up
tempo[mode] = max(0, (tempo[mode] - tempoincrement[mode]));
break;
case 3: //slow down
tempo[mode] += tempoincrement[mode];
break;
case 5: //brightness
strip.setBrightness(Bluetooth.read());
break;
}
}
}
void checktime() {
timepassed = millis() - lasttime;
if(timepassed > tempo[mode]){
runAnimation();
lasttime = millis();
}
}
void runAnimation() {
strip.clear();
switch (mode) {
case 0: //off
break;
case 1: //rainbow 1
color += 182;
for(int i = 0; i < LED_COUNT; i++){
colorbuf = strip.ColorHSV((color + (i * increment)));
strip.setPixelColor(i, colorbuf);
}
break;
case 2: //rainbow 2
color += 182;
strip.fill(strip.ColorHSV(color));
break;
case 3: //bouncing strip
color += 182;
colorbuf = strip.ColorHSV(color);
if (direction) {
pixel++;
if ((pixel + length) > last - 1) {
direction = false;
}
}
else {
pixel--;
if (pixel < 1) {
direction = true;
}
}
strip.fill(colorbuf, pixel, effect_length);
break;
case 4: //Christmas lights
direction = !direction;
for(int i = 0; i < LED_COUNT; i += effect_length){
if((i%(effect_length * 2) == 0) == direction){
for(int j = 0; j < effect_length; j++){
strip.setPixelColor((i + j), strip.Color(255, 0, 0));
}
}
else {
for(int j = 0; j < effect_length; j++){
strip.setPixelColor((i + j), strip.Color(0, 255, 0));
}
}
}
break;
/* //EPILEPSY WARNING: READ DISCLAIMER IN README FIRST!
case 5: //strobe light
color++;
if(color > 23) {
color = 0;
}
if((color%6 == 0) || ((color - 2)%6 == 0)) {
strip.fill(strip.Color(127, 127, 127));
}
break;
*/
case 6: //fire brigade lights
pixel++;
if(pixel >= LED_COUNT){
pixel = 0;
}
for(int i = 0; i < effect_length; i++){
int pos = pixel + i;
if(pos >= LED_COUNT){
pos -= LED_COUNT;
}
strip.setPixelColor(pos, 0, 0, 255);
pos += LED_COUNT / 2;
if(pos >= LED_COUNT){
pos -= LED_COUNT;
}
strip.setPixelColor(pos, 0, 0, 255);
}
break;
case 7: //portal
for (int i = 0; i < LED_COUNT; i++){
brightness = position + i;
if (brightness >= LED_COUNT){
brightness -= LED_COUNT;
}
if (brightness >= (LED_COUNT / 2)){
brightness -= (LED_COUNT / 2);
brightness = 255 - brightness;
brightness = map(brightness, 235, 255, 0, 255);
strip.setPixelColor(i, brightness, (brightness / 3), 0);
}
else{
brightness = 255 - brightness;
brightness = map(brightness, 235, 255, 0, 255);
strip.setPixelColor(i, 0, 0, brightness);
}
}
position++;
if (position > LED_COUNT){
position -= LED_COUNT;
}
break;
case 8: //police lights
direction = !direction;
for(int i = 0; i < LED_COUNT; i += effect_length){
if((i%(effect_length * 2) == 0) == direction){
for(int j = 0; j < effect_length; j++){
strip.setPixelColor((i + j), strip.Color(255, 0, 0));
}
}
else {
for(int j = 0; j < effect_length; j++){
strip.setPixelColor((i + j), strip.Color(0, 0, 255));
}
}
}
break;
case 9: //knight rider
for(int i = 0; i < effect_length; i++){
strip.setPixelColor((position + i), 255, 0, 0);
}
if(direction){
position++;
if(position >= LED_COUNT - effect_length){
direction = !direction;
}
}
else{
position--;
if(position <= 0){
direction = !direction;
}
}
break;
case 10: //warm white
for(int i = 0; i < LED_COUNT; i++){
strip.setPixelColor(i, 255, 120, 0);
}
break;
}
strip.show();
}