-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChopperRandoEye.ino
491 lines (413 loc) · 15 KB
/
ChopperRandoEye.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
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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
//Random Eye and LED Ladder patterns for Chopper's Dome
//Uses NeoPatterns
//Hacked by Eebel 18 April 2021
//work in progress
//Updated sketch to use NeoPatterns 3.1.1 on 7 Sep 2023
//Added Pericspope code 24 Nov 2023
#include "Arduino.h"
#include <Adafruit_NeoPixel.h>
#include "NeoPatterns.hpp"
//#ifdef __AVR__
// #include <avr/power.h> // Required for 16 MHz Adafruit Trinket
//#endif
#define LEDPAD //uncomment if using three NeoPixal Pads instead of an LED strip
// Which pin on the Arduino is connected to the NeoPixels?
#define EYEPIN 6 // Arduino pin to attach the Eyes
#define LADDERPIN 7 //Arduino pin to attach the LED Ladder
#define PERISCOPEPIN 8 //Periscope LED
// How many NeoPixels are attached to the Eyes?
#ifdef LEDPAD
int EYENUM = 3;
int eyeOne = 0;
int eyeTwo = 1;
int eyeThree = 2;
//#define EYENUM 3 //if using just thre NeoPixel LEDs
#else
int EYENUM = 8;
int eyeOne = 1;
int eyeTwo = 4;
int eyeThree = 7;
// #define EYENUM 8 // If using an LED Strip you need 8 to span the eyes
#endif
#define LADDERNUM 16//16//7//Number of Ladder LEDs
// When setting up the NeoPixel library, we tell it how many pixels,
// and which pin to use to send signals. Note that for older NeoPixel
// strips you might need to change the third parameter -- see the
// strandtest example for more information on possible values.
//Adafruit_NeoPixel pixels(EYENUM, EYEPIN, NEO_GRB + NEO_KHZ800);//Chopper's Eyes
// onComplete callback functions
void EyePatterns(NeoPatterns *aLedsPtr);
void TwoPatterns(NeoPatterns *aLedsPtr);
void PeriscopePatterns(NeoPatterns *aLedsPtr);
// construct the NeoPatterns instances
NeoPatterns neoEye = NeoPatterns(EYENUM, EYEPIN, NEO_GRB + NEO_KHZ800, &EyePatterns);
NeoPatterns ladder = NeoPatterns(LADDERNUM, LADDERPIN, NEO_GRB + NEO_KHZ800, &TwoPatterns);
NeoPatterns periscope = NeoPatterns(1, PERISCOPEPIN, NEO_GRB + NEO_KHZ800, &PeriscopePatterns);
/////Declarations
int RandoEyeVal();//Find a random eye to manipulate
void standardEyeLights(); //Steady state eye lighting
void randomEyeLights(); //Rando eye animations
void flickAAA(int flickB, int flickG, int flickR);//Flicker Routine
void powerGlitch(int flickB, int flickG, int flickR); //Power glitch animation
//void MultiPatterns(NeoPatterns *aLedsPtr);//NeoPatterns handler
#define DELAYVAL 500 // Time (in milliseconds) to pause between pixels
void setup() {
// These lines are specifically to support the Adafruit Trinket 5V 16 MHz.
// Any other board, you can remove this part (but no harm leaving it):
//#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
// clock_prescale_set(clock_div_1);
//#endif
// END of Trinket-specific code.
Serial.begin(115200);
// Just to know which program is running on my Arduino
Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing library version " VERSION_NEOPATTERNS));
//ladder.begin(); // This sets the pin.
neoEye.begin();
ladder.begin();
periscope.begin();
//Initial Colors
// pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
// pixels.setPixelColor(1, pixels.Color(90, 90, 0));
// pixels.setPixelColor(4, pixels.Color(0, 50, 255));
// pixels.setPixelColor(7, pixels.Color(0, 50, 255));
// pixels.show();
neoEye.setPixelColor(eyeOne, 90, 90, 0);
neoEye.setPixelColor(eyeTwo, 0, 50, 255);
neoEye.setPixelColor(eyeThree, 0, 50, 255);
neoEye.show();
periscope.setPixelColor(1, 0,50,200);
periscope.show();
/*
* First pattern ColorWipe
*/
Serial.println("ColorWipe");
//ladder.ColorWipe(COLOR32(0, 0, 4), 50, REVERSE); // light Blue
ladder.ColorWipe(COLOR32_WHITE_HALF,50);
ladder.updateAndWaitForPatternToStop();
delay(100);
/*
* Second pattern - RainbowCycle
*/
Serial.println("RainbowCycle");
ladder.RainbowCycle(10);
ladder.updateAndWaitForPatternToStop();
delay(100);
/*
* Third pattern - rocket
*/
Serial.println("Rocket");
ladder.ScannerExtended(COLOR32_WHITE_HALF, 7, 20, 0, FLAG_SCANNER_EXT_VANISH_COMPLETE);
ladder.updateAndWaitForPatternToStop();
delay(100);
/*
* Now trigger the automatic patterns
*/
TwoPatterns(&ladder);
EyePatterns(&neoEye);
PeriscopePatterns(&periscope);
Serial.println("started");
randomSeed(1234);
//NeoPixelBar24.begin(); // This sets the output pin.
/*
* Start the patterns
*/
//LowerNeoPixelBar.ColorWipe(COLOR32_GREEN_QUARTER, 80);
//MiddleNeoPixelBar.ScannerExtended(COLOR32_BLUE_HALF, 2, 60, 2, FLAG_SCANNER_EXT_ROCKET | FLAG_SCANNER_EXT_START_AT_BOTH_ENDS);
//UpperNeoPixelBar.ColorWipe(COLOR32_RED_QUARTER, 80, 0, DIRECTION_DOWN);
}
void loop() {
//NeoPatterns Area
ladder.update();
neoEye.update();
periscope.update();
//Serial.println("Updated ladder:");
delay(10);
}
void standardEyeLights(){
neoEye.clear();
neoEye.Color(eyeOne, 90, 90, 0);
neoEye.Color(eyeTwo, 0, 50, 255);
neoEye.Color(eyeThree, 0, 50, 255);
neoEye.show();
}
//}
//void flickAAA(int flickB, int flickG, int flickR)
//{
// // Flicker Chosen Light
// int randoEye = random(0,3);
// int eyeToJitter = RandoEyeVal();// 4;// randoEye;
// Serial.print ("RandoEye: ");
// Serial.println(randoEye);
//
// int flickTimes = random(7, 22);
//
// for(int i=0; i<flickTimes; i++){
// pixels.setPixelColor(eyeToJitter, pixels.Color(flickB, flickG, flickR));
// //Serial.print ("Flicker: ");
// //Serial.println(eyeToJitter);
// delay(50 );
// pixels.show();
// pixels.setPixelColor(eyeToJitter, pixels.Color(flickR, flickB, flickG));
// //pixels.setPixelColor(eyeToJitter, pixels.Color(0, 0, 0));
// delay(50);
// pixels.show();
// //Serial.print ("OFF: ");
// //Serial.println(eyeToJitter);
// }
//}
//void powerGlitch(int flickB, int flickG, int flickR){
// //power glitches so everything sputters
// pixels.setPixelColor(1, pixels.Color(flickR, flickB, flickG));
// pixels.setPixelColor(4, pixels.Color(flickR, flickB, flickG));
// pixels.setPixelColor(7, pixels.Color(flickR, flickB, flickG));
// pixels.show();
// delay(35);
//
// pixels.setPixelColor(1, pixels.Color(0, 0, 0));
// pixels.setPixelColor(4, pixels.Color(0, 0, 0));
// pixels.setPixelColor(7, pixels.Color(0, 0, 0));
// pixels.show();
// delay(8);
//}
//int RandoEyeVal(){
// //This function returns a valid random eye to operate on
// int randoNum = random (0,2);
// //int returnVal = 1;
//
// switch (randoNum){
// case 0:
// return eyeOne;//1;
// break;
// case 1:
// return eyeTwo;//4;
// break;
// case 2:
// return eyeThree;//7;
// break;
// }
//
//}
/*
* Simple handler for switching between 2 patterns
*/
void TwoPatterns(NeoPatterns *aLedsPtr) {
//static int8_t sState = 7;
static int8_t repeat = random(4,11);
static int8_t pattCount = (8+1);//number of cases +1
static int8_t sState = random(0,pattCount);
//#if defined(__AVR__)
// uint32_t tRandom = random();
//#else
uint32_t tRandom = random(__UINT32_MAX__);
//#endif
uint8_t tDuration = random(100,300);//random(20, 120);
uint8_t tColor1 = tRandom;
uint8_t tColor2 = tRandom >> 8;
switch (sState) {
//switch (1) {
case 0:
// Scanner - use random mode and direction
aLedsPtr->ScannerExtended(NeoPatterns::Wheel(tColor1), 3, tDuration, repeat,
(tRandom & FLAG_SCANNER_EXT_CYLON) | (tRandom & FLAG_SCANNER_EXT_VANISH_COMPLETE)
| (tRandom & FLAG_SCANNER_EXT_START_AT_BOTH_ENDS), ((tRandom >> 8) & DIRECTION_DOWN));
sState = random(0,pattCount);
Serial.println("Random");
break;
case 1:
// Fade - use random direction
aLedsPtr->Fade(NeoPatterns::Wheel(tColor1), COLOR32_WHITE, repeat+12, tDuration);
sState = random(0,pattCount);
Serial.println("Fade");
break;
case 2:
aLedsPtr->ColorWipe(COLOR32_WHITE, 50,FLAG_SCANNER_EXT_START_AT_BOTH_ENDS,DIRECTION_DOWN);
sState = random(0,pattCount);
Serial.println("ColorWipe");
break;
case 3:
aLedsPtr->Heartbeat(COLOR32_WHITE, 50, repeat);
sState = random(0,pattCount);
Serial.println("Heartbeat");
break;
case 4:
//aLedsPtr->RainbowCycle(50, DIRECTION_UP);
//aLedsPtr->ScannerExtended(COLOR32_WHITE, 7, 20, 0, FLAG_SCANNER_EXT_VANISH_COMPLETE,((tRandom >> 8) & DIRECTION_DOWN));
aLedsPtr->ScannerExtended(COLOR32_WHITE, 7, 20, 0, FLAG_SCANNER_EXT_VANISH_COMPLETE, DIRECTION_DOWN);
//aLedsPtr->updateAndWaitForPatternToStop();
sState = random(0,pattCount);
Serial.println("Rocket");
break;
case 5:
aLedsPtr->RainbowCycle(50, DIRECTION_DOWN);
sState = random(0,pattCount);
Serial.println("RainbowCylceDown");
break;
case 6:
aLedsPtr->Fire(30, 40, DIRECTION_DOWN); // OK Fire(30, 260)is also OK
sState = random(0,pattCount);
Serial.println("Fire");
break;
case 7:
aLedsPtr->ScannerExtended(COLOR32_WHITE, 2, tDuration, 15,
FLAG_SCANNER_EXT_CYLON , ((tRandom >> 8) & DIRECTION_DOWN));
sState = random(0,pattCount);
Serial.println("ScannerExtended");
break;
case 8:
/*
* Non blocking delay implemented as pattern :-)
*/
aLedsPtr->Delay(10);
sState = random(0,pattCount);
Serial.println("Delay");
break;
default:
sState = random(0,pattCount);
Serial.println("ERROR");
break;
}
// Serial.print(" ActiveLadderPattern=");
// aLedsPtr->printPatternName(aLedsPtr->ActivePattern, &Serial);
// Serial.print("|");
// Serial.print(aLedsPtr->ActivePattern);
// Serial.println();
//sState++;
}
void EyePatterns(NeoPatterns *aLedsPtr) {
//static int8_t sState = 0;
static int8_t sState = random(0,3);
//#if defined(__AVR__)
// uint32_t tRandom = random();
//#else
uint32_t tRandom = random(__UINT32_MAX__);
//#endif
uint8_t tDuration = random(20, 120);
uint8_t tColor1 = tRandom;
uint8_t tColor2 = tRandom >> 8;
int randoTime = random(1000);
switch (sState) {
case 0:
// Scanner - use random mode and direction
aLedsPtr->ScannerExtended(NeoPatterns::Wheel(tColor1), 4, tDuration, 1,
(tRandom & FLAG_SCANNER_EXT_CYLON) | (tRandom & FLAG_SCANNER_EXT_VANISH_COMPLETE)
| (tRandom & FLAG_SCANNER_EXT_START_AT_BOTH_ENDS), ((tRandom >> 8) & DIRECTION_DOWN));
sState = random(1,4);
break;
case 1:
// Stripes - use random direction
aLedsPtr->Stripes(NeoPatterns::Wheel(tColor1), 5, NeoPatterns::Wheel(tColor2), 3, 2 * aLedsPtr->numPixels(), tDuration,
(tRandom & DIRECTION_DOWN));
sState = random(2,4);
break;
case 2:
//Standard Eye Colors;
#ifdef LEDPAD
aLedsPtr->setPixelColor(eyeOne, aLedsPtr->Color(90, 190, 0));
aLedsPtr->setPixelColor(eyeTwo, aLedsPtr->Color(0, 50, 255));
aLedsPtr->setPixelColor(eyeThree, aLedsPtr->Color(0, 50, 255));
#else
aLedsPtr->setPixelColor(0, aLedsPtr->Color(0, 0, 0));
aLedsPtr->setPixelColor(1, aLedsPtr->Color(90, 90, 0));//Active
aLedsPtr->setPixelColor(2, aLedsPtr->Color(0, 0, 0));
aLedsPtr->setPixelColor(3, aLedsPtr->Color(0, 0, 0));
aLedsPtr->setPixelColor(4, aLedsPtr->Color(0, 50, 255));//Active
aLedsPtr->setPixelColor(5, aLedsPtr->Color(0, 0, 0));
aLedsPtr->setPixelColor(6, aLedsPtr->Color(0, 0, 0));
aLedsPtr->setPixelColor(7, aLedsPtr->Color(0, 50, 255));//Active
aLedsPtr->setPixelColor(8, aLedsPtr->Color(0, 0, 0));
#endif
aLedsPtr->show();
aLedsPtr->Delay((DELAYVAL+randoTime)*3);
sState = random(0,4);
break;
case 3:
/*
* Non blocking delay implemented as pattern :-)
*/
//aLedsPtr->clear();
aLedsPtr->Delay(1000);
sState = random(0,4);// go steady//-1; // Start from beginning
break;
default:
sState =2;
Serial.println("ERROR");
break;
}
// Serial.print(" ActiveEyePattern=");
// aLedsPtr->printPatternName(aLedsPtr->ActivePattern, &Serial);
// Serial.print("|");
// Serial.print(aLedsPtr->ActivePattern);
// Serial.print(" sState: ");
// Serial.print (sState);
// Serial.println();
//sState++;
}
void PeriscopePatterns(NeoPatterns *aLedsPtr) {
//static int8_t sState = 0;
static int8_t sState = random(0,3);
//#if defined(__AVR__)
// uint32_t tRandom = random();
//#else
uint32_t tRandom = random(__UINT32_MAX__);
//#endif
uint8_t tDuration = random(20, 120);
uint8_t tColor1 = tRandom;
uint8_t tColor2 = tRandom >> 8;
int randoTime = random(1000);
switch (sState) {
case 0:
// Scanner - use random mode and direction
aLedsPtr->ScannerExtended(NeoPatterns::Wheel(tColor1), 4, tDuration, 1,
(tRandom & FLAG_SCANNER_EXT_CYLON) | (tRandom & FLAG_SCANNER_EXT_VANISH_COMPLETE)
| (tRandom & FLAG_SCANNER_EXT_START_AT_BOTH_ENDS), ((tRandom >> 8) & DIRECTION_DOWN));
sState = random(1,4);
break;
case 1:
// Stripes - use random direction
aLedsPtr->Stripes(NeoPatterns::Wheel(tColor1), 5, NeoPatterns::Wheel(tColor2), 3, 2 * aLedsPtr->numPixels(), tDuration,
(tRandom & DIRECTION_DOWN));
sState = random(2,4);
break;
case 2:
//Standard Eye Colors;
#ifdef LEDPAD
aLedsPtr->setPixelColor(eyeOne, aLedsPtr->Color(90, 190, 0));
aLedsPtr->setPixelColor(eyeTwo, aLedsPtr->Color(0, 50, 255));
aLedsPtr->setPixelColor(eyeThree, aLedsPtr->Color(0, 50, 255));
#else
aLedsPtr->setPixelColor(0, aLedsPtr->Color(0, 0, 0));
aLedsPtr->setPixelColor(1, aLedsPtr->Color(90, 90, 0));//Active
aLedsPtr->setPixelColor(2, aLedsPtr->Color(0, 0, 0));
aLedsPtr->setPixelColor(3, aLedsPtr->Color(0, 0, 0));
aLedsPtr->setPixelColor(4, aLedsPtr->Color(0, 50, 255));//Active
aLedsPtr->setPixelColor(5, aLedsPtr->Color(0, 0, 0));
aLedsPtr->setPixelColor(6, aLedsPtr->Color(0, 0, 0));
aLedsPtr->setPixelColor(7, aLedsPtr->Color(0, 50, 255));//Active
aLedsPtr->setPixelColor(8, aLedsPtr->Color(0, 0, 0));
#endif
aLedsPtr->show();
aLedsPtr->Delay((DELAYVAL+randoTime)*3);
sState = random(0,4);
break;
case 3:
/*
* Non blocking delay implemented as pattern :-)
*/
//aLedsPtr->clear();
aLedsPtr->Delay(1000);
sState = random(0,4);// go steady//-1; // Start from beginning
break;
default:
sState =2;
Serial.println("ERROR");
break;
}
// Serial.print(" ActiveEyePattern=");
// aLedsPtr->printPatternName(aLedsPtr->ActivePattern, &Serial);
// Serial.print("|");
// Serial.print(aLedsPtr->ActivePattern);
// Serial.print(" sState: ");
// Serial.print (sState);
// Serial.println();
//sState++;
}