-
Notifications
You must be signed in to change notification settings - Fork 0
/
body_leds.ino
300 lines (269 loc) · 6.59 KB
/
body_leds.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
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
#define REDPIN 7
#define GREENPIN 8
#define BLUEPIN 6
#define FADESPEED 20 // make this higher to slow down
unsigned long int lastBodyLedLoop = 0;
int bodyI = 0;
unsigned long int resetTime=0;
unsigned long int startLedTime=0;
void bodyLedSetup() {
pinMode(REDPIN, OUTPUT);
pinMode(GREENPIN, OUTPUT);
pinMode(BLUEPIN, OUTPUT);
//setBodyLedRainbow();
}
int r, g, bl;
void simpleproof() {
if (r < 255) {
analogWrite(8, r);
r++;
}
else r = 0;
}
void bodyLedLoop() {
if (millis() - lastBodyLedLoop > FADESPEED) {
switch (body_led_state) {
case led_off: break;
case rainbow_cycle: idleLoop(); break;
case color_wipe: wipeLoop(body_color); break;
case color_pulse: pulseLoop(body_color); break;
}
bodyShow();
}
}
void resetLeds(){
r = 0; g = 0; bl = 0;
bodyShow();
}
void setBodyLedOff() {
body_led_state = led_off;
resetLeds();
}
void setBodyLedRainbow() {
body_led_state = rainbow_cycle;
r = 0; g = 0; bl = 255;
bodyShow();
}
void setBodyLedWipe(colors color) {
body_led_state = color_wipe;
body_color=color;
resetLeds();
}
void setBodyLedWipe() {
body_led_state = color_wipe;
resetLeds();
}
void setBodyLedPulse(colors color) {
body_led_state = color_pulse;
body_color=color;
resetLeds();
}
void setBodyLedPulse() {
body_led_state = color_pulse;
resetLeds();
}
void bodyLedUpdate(ledStates ledState) {
if (body_leds && body_led_state != ledState) {
bodyI=0;
switch (ledState) {
case color_pulse: setBodyLedPulse(); break;
case color_wipe: setBodyLedWipe(); break;
case rainbow_cycle: setBodyLedRainbow(); break;
case led_off: setBodyLedOff(); break;
}
}
}
void bodyLedUpdate(colors color) {
if(body_leds && body_color!=color){
body_color=color;
bodyI=0;
resetLeds();
}
}
void bodyLedUpdate(ledStates state, colors color) {
if (body_leds && (body_led_state != state || body_color!=color)) {
bodyI=0;
switch (state) {
case color_pulse: setBodyLedPulse(color); break;
case color_wipe: setBodyLedWipe(color); break;
case rainbow_cycle: setBodyLedRainbow(); break;
case led_off: setBodyLedOff(); break;
}
}
}
void bodyLedUpdate(ledStates state, colors color, unsigned long int timer) {
if (body_leds){
setLedTimer(timer);
if(body_led_state != state || body_color!=color) {
bodyI=0;
switch (state) {
case color_pulse: setBodyLedPulse(color); break;
case color_wipe: setBodyLedWipe(color); break;
case rainbow_cycle: setBodyLedRainbow(); break;
case led_off: setBodyLedOff(); break;
}
}
}
}
boolean ledTimer=false;
unsigned long int fullColorTime=0;
void wipeLoop(colors color) {
if (color == blueC) {
if (bl < 255) bl++;
} else if (color == redC) {
if (r < 255) r++;
} else if (color == greenC) {
if (g < 255) g++;
} else if (color == yellowC) {
if (r < 254) r = r + 2;
if (g < 125) g++;
} else if(color == lightBlueC){
if (bl < 254) bl=bl+2;
if (g < 254) g=g+2;
if (r<100) r++;
}else if(color == orangeC){
if (r < 250) r =r+5;
if (g < 50) g++;
}else if(color == redCrazy){
if(r<=235) r=r+20;
else r=55;
// int switchM=millis()-startLedTime%10;
// if(switchM<5){
// r=250;
// }else{
// r=0;
// }
}
if(ledTimer && millis()-fullColorTime>resetTime){
ledTimer=false;
resetLeds();
bodyLedUpdate(led_off);
}
// else if (color == head_strip.Color(255, 100, 0)) {
// if (r < 255) r++;
// if (g < 100) g++;
// }} else if (color == head_strip.Color(0, 255, 255)) {
// if (g < 255) g++;
// if (bl < 255) bl++;
// } else if (color == head_strip.Color(255, 0, 255)) {
// if (r < 255) r++;
// if (bl < 255) bl++;
}
void setLedTimer(){
fullColorTime=millis();
ledTimer=true;
}
void setLedTimer(unsigned long int reset_time){
resetTime=reset_time;
fullColorTime=millis();
ledTimer=true;
}
void pulseLoop(colors color) {
if (color == blueC) {
if (bl < 255 && bodyI == 0) bl++;
else if (bodyI == 0) bodyI = 1;
if (bl > 0 && bodyI == 1) bl--;
else if (bodyI == 1) bodyI = 0;
}
else if (color == redC) {
if (r < 255 && bodyI == 0) r++;
else if (bodyI == 0) bodyI = 1;
if (r > 0 && bodyI == 1) r--;
else if (bodyI == 1) bodyI = 0;
}
else if (color == greenC) {
if (g < 255 && bodyI == 0) g++;
else if (bodyI == 0) bodyI = 1;
if (g > 0 && bodyI == 1) g--;
else if (bodyI == 1) bodyI = 0;
}
else if (color == yellowC) {
if (bodyI == 0) {
if (r <= 248) r = r + 2;
if (g < 125) g++;
if (r == 250) bodyI = 1;
} else if (bodyI == 1) {
if (r > 0) r = r - 2;
if (g > 0) g--;
if (r == 0) bodyI = 0;
}
}else if(color == orangeC){
if(bodyI==0){
if (r < 250) r =r+5;
if (g < 50) g++;
if(r==250) bodyI = 1;
}else if (bodyI == 1) {
if (r > 0) r = r - 5;
if (g > 0) g--;
if (r == 0) bodyI = 0;
}
}
if(ledTimer && millis()-fullColorTime>resetTime){
ledTimer=false;
bodyLedUpdate(led_off);
headLedUpdate(rainbow_cycle);
}
}
//
//void bodyLedUpdate(uint32_t color) {
// if(color==head_strip.Color(0, 0, 255)){
// r = 0; g = 0; bl = 255;
// }else if(color == head_strip.Color(255, 0, 0)){
// r = 255; g = 0; bl = 0;
// }else if(color == head_strip.Color(0, 255, 0)){
// r = 0; g = 255; bl = 0;
// }else if(color == head_strip.Color(0, 255, 255)){
// r = 0; g = 255; bl = 255;
// }else if(color == head_strip.Color(255, 0, 255)){
// r = 255; g = 0; bl = 255;
// }else if(color == head_strip.Color(255, 170, 0)){
// r = 255; g = 170; bl = 0;
// }else if(color == head_strip.Color(255, 100, 0)){
// r = 255; g = 100; bl = 0;
// }
//}
//
void idleLoop() {
if (bodyI == 0) {
r++;
analogWrite(REDPIN, r);
lastBodyLedLoop = millis();
if (r == 255) bodyI = 1;
}
if (bodyI == 1) {
bl--;
analogWrite(BLUEPIN, bl);
lastBodyLedLoop = millis();
if (bl == 1) bodyI = 2;
}
if (bodyI == 2) {
g++;
analogWrite(GREENPIN, g);
lastBodyLedLoop = millis();
if (g == 255) bodyI = 3;
}
if (bodyI == 3) {
r--;
analogWrite(REDPIN, r);
lastBodyLedLoop = millis();
if (r == 1) bodyI = 4;
}
if (bodyI == 4) {
bl++;
analogWrite(BLUEPIN, bl);
lastBodyLedLoop = millis();
if (bl == 255) bodyI = 5;
}
if (bodyI == 5) {
g--;
analogWrite(GREENPIN, g);
lastBodyLedLoop = millis();
if (g == 1) bodyI = 0;
}
}
void bodyShow() {
analogWrite(REDPIN, r);
analogWrite(GREENPIN, g);
analogWrite(BLUEPIN, bl);
lastBodyLedLoop = millis();
}