-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConsoleLED.cpp
More file actions
922 lines (848 loc) · 28.3 KB
/
ConsoleLED.cpp
File metadata and controls
922 lines (848 loc) · 28.3 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
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
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
#include <Arduino.h>
#include <Stream.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
//AWS
#include "sha256.h"
#include "Utils.h"
//WEBSockets
#include <Hash.h>
#include <WebSocketsClient.h>
//MQTT PAHO
#include <SPI.h>
#include <IPStack.h>
#include <Countdown.h>
#include <MQTTClient.h>
//AWS MQTT Websocket
#include "Client.h"
#include "AWSWebSocketClient.h"
#include "CircularByteBuffer.h"
#include <string>
//LED ADDITIONS START
#define FASTLED_ESP8266_RAW_PIN_ORDER
#define FASTLED_INTERNAL
#define FASTLED_INTERRUPT_RETRY_COUNT 0
//#define FASTLED_ALLOW_INTERRUPTS 0
#include <FastLED.h>
#define CALIBRATION_TEMPERATURE TypicalLEDStrip
CRGB leds[NUM_LEDS];
CRGB leds_new[NUM_LEDS];
uint8_t BeatsPerMinute = 90;
int r = 0;
int g = 0;
int b = 0;
bool homemade_method = false;
int FRAMES_PER_SECOND = 60;
uint8_t gHue = 0; // rotating "base color" used by many of the patterns
bool rainbowMarchOn = false;
CRGBPalette16 currentPalette;
CRGBPalette16 targetPalette;
bool beatWaveOn = false;
bool rainbowBeatOn = false;
bool twoSinPalOn = false;
unsigned long previousMillis;
uint8_t thishue; // You can change the starting hue value for the first wave.
uint8_t rainbowHue;
uint8_t thathue; // You can change the starting hue for other wave.
uint8_t thisrot; // You can change how quickly the hue rotates for this wave. Currently 0.
uint8_t thatrot; // You can change how quickly the hue rotates for the other wave. Currently 0.
uint8_t allsat; // I like 'em fully saturated with colour.
uint8_t thisdir;
uint8_t thatdir;
uint8_t alldir; // You can change direction.
int8_t thisspeed; // You can change the speed.
int8_t thatspeed; // You can change the speed.
uint8_t allfreq; // You can change the frequency, thus overall width of bars.
int thisphase; // Phase change value gets calculated.
int thatphase; // Phase change value gets calculated.
uint8_t thiscutoff; // You can change the cutoff value to display this wave. Lower value = longer wave.
uint8_t thatcutoff; // You can change the cutoff value to display that wave. Lower value = longer wave.
int thisdelay; // Standard delay. .
uint8_t fadeval; // Use to fade the led's of course.
CRGBPalette16 thisPalette;
CRGBPalette16 thatPalette;
TBlendType currentBlending; // NOBLEND or LINEARBLEND
#define qsubd(x, b) ((x>b)?b:0) // A digital unsigned subtraction macro. if result <0, then => 0. Otherwise, take on fixed value.
#define qsuba(x, b) ((x>b)?x-b:0) // Unsigned subtraction macro. if result <0, then => 0
uint8_t deltahue = 10; // Hue change between pixels.
uint8_t rainbowDelta = 10;
int BlendR1 = 250;
int BlendR2 = 0;
int BlendB1 = 75;
int BlendB2 = 250;
int BlendG1 = 75;
int BlendG2 = 250;
int BlendGroup = 24;
bool BlendFirstColor = true;
bool BlendCycleOn = false;
bool FadeCycleOn = false;
int max_brightness = 180;
int cur_brightness = 180;
bool FadeFirstColor = true;
bool FadeBrightFlip = false;
bool FirstFade = true;
CRGB endclr;
CRGB midclr;
bool FadeBlendRainbow = true;
bool FadeBlendRainbowSet = true;
unsigned long FadeBlendMillStart;
//LED ADDITIONS STOP
//AWS IOT config, change these:
#define DATA_PIN 15
#define NUM_LEDS 24
char wifi_ssid[] = "Cats in Space";
char wifi_password[] = "meowmixer";
char aws_endpoint[] = "AWS ENDPOINT";
char aws_key[] = "AWS KEY";
char aws_secret[] = "AWS SECRET";
char aws_region[] = "us-east-1";
const char* aws_topic = "$aws/things/gamingStrips/shadow/update/delta";
const char* aws_den = "$aws/things/denEsp/shadow/update/delta";
int port = 443;
//MQTT config
const int maxMQTTpackageSize = 512;
const int maxMQTTMessageHandlers = 1;
ESP8266WiFiMulti WiFiMulti;
AWSWebSocketClient awsWSclient(1000);
IPStack ipstack(awsWSclient);
MQTT::Client<IPStack, Countdown, maxMQTTpackageSize, maxMQTTMessageHandlers> *client = NULL;
long connection = 0;
char* generateClientID () {
char* cID = new char[23]();
for (int i=0; i<22; i+=1)
cID[i]=(char)random(1, 256);
return cID;
}
int arrivedcount = 0;
void setScene(String text){
if(text == "fade"){
FadeCycleOn = true;
BlendCycleOn = false;
homemade_method = true;
rainbowMarchOn = false;
rainbowBeatOn = false;
beatWaveOn = false;
twoSinPalOn = false;
Serial.println("Fade Cycle");
}
if(text == "blend"){
FadeCycleOn = false;
BlendCycleOn = true;
homemade_method = true;
rainbowMarchOn = false;
rainbowBeatOn = false;
beatWaveOn = false;
twoSinPalOn = false;
Serial.println("Blend Cycle");
}
if(text == "friends"){
FadeCycleOn = false;
BlendCycleOn = false;
homemade_method = true;
rainbowMarchOn = false;
rainbowBeatOn = false;
beatWaveOn = false;
twoSinPalOn = true;
Serial.println("Two Sin Pal");
}
if (text == "beat_wave") {
homemade_method = true;
rainbowMarchOn = false;
rainbowBeatOn = false;
beatWaveOn = true;
twoSinPalOn = false;
FadeCycleOn = false;
BlendCycleOn = false;
Serial.println("Beat Wave");
}
if (text == "rainbow_march") {
homemade_method = true;
rainbowMarchOn = true;
rainbowBeatOn = false;
beatWaveOn = false;
twoSinPalOn = false;
FadeCycleOn = false;
BlendCycleOn = false;
Serial.println("Rainbow March");
}
if (text == "rainbow_beat") {
homemade_method = true;
rainbowMarchOn = false;
rainbowBeatOn = true;
beatWaveOn = false;
twoSinPalOn = false;
FadeCycleOn = false;
BlendCycleOn = false;
Serial.println("Rainbow Beat");
}
if (text == "rainbow") {
homemade_method = false;
Serial.println("Rainbow");
rainbow_call();
}
if (text == "glitter") {
homemade_method = false;
Serial.println("Rainbow With Glitter");
rainbowWithGlitter_call();
}
if (text == "confetti") {
homemade_method = false;
Serial.println("Confetti");
confetti_call();
}
if (text == "twinkle") {
Serial.println("twinkle");
homemade_method = false;
confetti_color_call();
}
if (text == "sign") {
homemade_method = false;
Serial.println("Sinelon");
sinelon_call();
}
if (text == "music") {
homemade_method = false;
Serial.println("BPM");
bpm_call();
}
if (text.startsWith("bpm=")) {
homemade_method = false;
String npm_int = text.substring(text.indexOf("=") + 1, text.length());
int beats = npm_int.toInt();
BeatsPerMinute = beats;
Serial.println("BPM SET");
Serial.println(npm_int);
bpm_call();
}
if (text.startsWith("frames=")) {
String npm_int = text.substring(text.indexOf("=") + 1, text.length());
int beats = npm_int.toInt();
FRAMES_PER_SECOND = beats;
Serial.println("Frames SET");
Serial.println(FRAMES_PER_SECOND);
}
if (text.startsWith("grouping=")) {
String npm_int = text.substring(text.indexOf("=") + 1, text.length());
int beats = npm_int.toInt();
Serial.println("Groups SET");
Serial.println(beats);
BlendGroup = beats;
}
if (text.startsWith("brightness=")) {
String npm_int = text.substring(text.indexOf("=") + 1, text.length());
int beats = npm_int.toInt();
if (homemade_method == true) {
FastLED.setBrightness(beats);
max_brightness = beats;
cur_brightness = beats;
for (int i = 0; i < NUM_LEDS; i++) {
leds_new[i] = leds[i];
};
for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = leds_new[i];
};
FastLED.show();
} else {
FastLED.setBrightness(beats);
}
Serial.println("Brightness SET");
Serial.println(beats);
}
if (text == "juggle") {
Serial.println("Juggle");
juggle_call();
}
if (text == "clear") {
homemade_method = true;
rainbowMarchOn = false;
rainbowBeatOn = false;
beatWaveOn = false;
twoSinPalOn = false;
FadeCycleOn = false;
BlendCycleOn = false;
Serial.println("Clear");
for (int k = 0; k < NUM_LEDS; k++) {
Serial.println(k);
leds[k] = CRGB::Black;
}
FastLED.show();
}
if (text.startsWith("solid=")){
homemade_method = true;
rainbowMarchOn = false;
rainbowBeatOn = false;
beatWaveOn = false;
twoSinPalOn = false;
FadeCycleOn = false;
BlendCycleOn = false;
String color = text.substring(text.indexOf("=") + 1, text.length());
long number = strtol( &color[1], NULL, 16);
r = number >> 16;
g = number >> 8 & 0xFF;
b = number & 0xFF;
for (int k = 0; k < NUM_LEDS; k++) {
leds[k].setRGB(r, g, b);
}
FastLED.show();
Serial.println("Solid SET");
Serial.println(r);
Serial.println(g);
Serial.println(b);
}
if(text.startsWith("color1")){
homemade_method = true;
rainbowMarchOn = false;
rainbowBeatOn = false;
beatWaveOn = false;
twoSinPalOn = false;
String color = text.substring(text.indexOf("=") + 1, text.length());
long number = strtol( &color[1], NULL, 16);
r = number >> 16;
g = number >> 8 & 0xFF;
b = number & 0xFF;
BlendR1 = r;
BlendG1 = g;
BlendB1 = b;
for (int k = 0; k < NUM_LEDS; k++) {
leds[k].setRGB(r, g, b);
}
FastLED.show();
Serial.println("Color 1 SET");
Serial.println(r);
Serial.println(g);
Serial.println(b);
delay(800);
}
if(text.startsWith("color2")){
homemade_method = true;
rainbowMarchOn = false;
rainbowBeatOn = false;
beatWaveOn = false;
twoSinPalOn = false;
String color = text.substring(text.indexOf("=") + 1, text.length());
long number = strtol( &color[1], NULL, 16);
BlendR2 = number >> 16;
BlendG2 = number >> 8 & 0xFF;
BlendB2 = number & 0xFF;
for (int k = NUM_LEDS/2; k < NUM_LEDS; k++) {
leds[k].setRGB(BlendR2, BlendG2, BlendB2);
}
FastLED.show();
Serial.println("Color 2 SET");
delay(800);
}
}
void messageArrived(MQTT::MessageData& md)
{
MQTT::Message &message = md.message;
Serial.print("Message ");
Serial.print(++arrivedcount);
Serial.print(" arrived: qos ");
Serial.print(message.qos);
Serial.print(", retained ");
Serial.print(message.retained);
Serial.print(", dup ");
Serial.print(message.dup);
Serial.print(", packetid ");
Serial.println(message.id);
Serial.print("Payload ");
char* msg = new char[message.payloadlen+1]();
memcpy (msg,message.payload,message.payloadlen);
Serial.println(msg);
String msg_text = String(msg);
String state_text = msg_text.substring(msg_text.indexOf("scene") + 8, msg_text.indexOf("metadata") - 2);
String scene_text = state_text.substring(0, state_text.indexOf(",") - 1);
Serial.println(state_text);
Serial.println(scene_text);
setScene(scene_text);
delete msg;
}
bool connect () {
if (client == NULL) {
client = new MQTT::Client<IPStack, Countdown, maxMQTTpackageSize, maxMQTTMessageHandlers>(ipstack);
} else {
if (client->isConnected ()) {
client->disconnect ();
}
delete client;
client = new MQTT::Client<IPStack, Countdown, maxMQTTpackageSize, maxMQTTMessageHandlers>(ipstack);
}
//delay is not necessary... it just help us to get a "trustful" heap space value
delay (1000);
Serial.print (millis ());
Serial.print (" - conn: ");
Serial.print (++connection);
Serial.print (" - (");
Serial.print (ESP.getFreeHeap ());
Serial.println (")");
int rc = ipstack.connect(aws_endpoint, port);
if (rc != 1)
{
Serial.println("error connection to the websocket server");
return false;
} else {
Serial.println("websocket layer connected");
}
Serial.println("MQTT connecting");
MQTTPacket_connectData data = MQTTPacket_connectData_initializer;
data.MQTTVersion = 3;
char* clientID = generateClientID ();
data.clientID.cstring = clientID;
rc = client->connect(data);
delete[] clientID;
if (rc != 0)
{
Serial.print("error connection to MQTT server");
Serial.println(rc);
return false;
}
Serial.println("MQTT connected");
return true;
}
//subscribe to a mqtt topic
void subscribe () {
//subscript to a topic
int rc = client->subscribe(aws_topic, MQTT::QOS0, messageArrived);
if (rc != 0) {
Serial.print("rc from MQTT subscribe is ");
Serial.println(rc);
return;
}
Serial.println("MQTT subscribed");
}
//send a message to a mqtt topic
void sendmessage () {
//send a message
MQTT::Message message;
char buf[100];
strcpy(buf, "{\"state\":{\"reported\":{\"on\": false}, \"desired\":{\"on\": false}, \"delta\":{\"scene\": solid=#00ffff},{\"state\":rainbow}}");
message.qos = MQTT::QOS0;
message.retained = false;
message.dup = false;
message.payload = (void*)buf;
message.payloadlen = strlen(buf)+1;
int rc = client->publish(aws_den, message);
}
void setup() {
Serial.begin (115200);
delay (2000);
Serial.setDebugOutput(1);
//LED SETUP STUFF START
analogWrite(DATA_PIN,0);
FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
FastLED.setBrightness(255);
currentPalette = RainbowColors_p;
currentBlending = LINEARBLEND;
thisPalette = RainbowColors_p;
thatPalette = RainbowColors_p;
resetvars();
//LED SETUP STUFF END
//fill with ssid and wifi password
WiFiMulti.addAP(wifi_ssid, wifi_password);
Serial.println ("connecting to wifi");
while(WiFiMulti.run() != WL_CONNECTED) {
delay(100);
Serial.print (".");
}
Serial.println ("\nconnected");
//fill AWS parameters
awsWSclient.setAWSRegion(aws_region);
awsWSclient.setAWSDomain(aws_endpoint);
awsWSclient.setAWSKeyID(aws_key);
awsWSclient.setAWSSecretKey(aws_secret);
awsWSclient.setUseSSL(true);
if (connect ()){
for (int k = 0; k < NUM_LEDS; k++) {
leds[k].setRGB(0, 255, 255);
}
FastLED.show();
subscribe ();
sendmessage ();
}
FirstFade = true;
FadeCycleOn = true;
homemade_method = true;
max_brightness = cur_brightness;
}
//SEPCIAL LED NETHOD START
typedef void (*SimplePatternList[])();
SimplePatternList gPatterns = { rainbow, rainbowWithGlitter, confetti, sinelon, bpm, juggle, confettiColor };
uint8_t gCurrentPatternNumber = 0; // Index number of which pattern is current
//SEPCIAL LED NETHOD END
void loop() {
//keep the mqtt up and running
if (awsWSclient.connected ()) {
client->yield((1000 / FRAMES_PER_SECOND));
} else {
//handle reconnection
if (connect ()){
subscribe ();
}
}
//LED LOOP METHODS START
if (homemade_method == false) {
gPatterns[gCurrentPatternNumber]();
FastLED.show();
// insert a delay to keep the framerate modest
// do some periodic updates
EVERY_N_MILLISECONDS(1000 / FRAMES_PER_SECOND) {
gHue++; // slowly cycle the "base color" through the rainbow
}
// EVERY_N_SECONDS( 100 ) { nextPattern(); } // change patterns periodically
}
if(rainbowMarchOn){
rainbow_march();
FastLED.show();
}
if(rainbowBeatOn){
rainbow_beat();
FastLED.show();
}
if(beatWaveOn){
beatwave();
EVERY_N_MILLISECONDS(1000 / FRAMES_PER_SECOND) {
uint8_t maxChanges = 24;
nblendPaletteTowardPalette(currentPalette, targetPalette, maxChanges); // AWESOME palette blending capability.
}
EVERY_N_SECONDS(5) { // Change the target palette to a random one every 5 seconds.
targetPalette = CRGBPalette16(CHSV(random8(), 255, random8(128,255)), CHSV(random8(), 255, random8(128,255)), CHSV(random8(), 192, random8(128,255)), CHSV(random8(), 255, random8(128,255)));
}
FastLED.show();
FastLED.delay(1000 / FRAMES_PER_SECOND);
}
if(twoSinPalOn){
ChangeMe();
EVERY_N_MILLISECONDS(1000 / FRAMES_PER_SECOND) {
two_sin(); // Routine is still delay based, but at least it's now a non-blocking day.
}
FastLED.show();
FastLED.delay(1000 / (FRAMES_PER_SECOND*2));
}
if(BlendCycleOn){
blendCycle();
FastLED.show();
EVERY_N_MILLISECONDS(212 / FRAMES_PER_SECOND);
}
if(FadeCycleOn){
faceCycle();
for( int i = 0; i < NUM_LEDS; i++) {
if(i%BlendGroup == 0){
if(BlendFirstColor){
BlendFirstColor = false;
}else{
BlendFirstColor = true;
}
}
if(FadeFirstColor){
if(BlendFirstColor){
leds[i]=CRGB( BlendR1, BlendG1, BlendB1);
}else{
leds[i]=CRGB( BlendR2, BlendG2, BlendB2);
}
}else{
if(BlendFirstColor){
leds[i]=CRGB( BlendR2, BlendG2, BlendB2);
}else{
leds[i]=CRGB( BlendR1, BlendG1, BlendB1);
}
}
}
FastLED.show();
EVERY_N_MILLISECONDS(212 / FRAMES_PER_SECOND);
}
//LED LOOP METHODS END
}
//LED METHODS TO RUN START!
void faceCycle(){
BlendFirstColor = true;
if(max_brightness == 0){
if(FadeBlendRainbow){
if(FadeBlendRainbowSet){
FadeBlendMillStart = millis();
FadeBlendRainbowSet = false;
}
// if(FadeBlendMillStart <= millis() - 5000){
if(FirstFade == false){
Serial.println("I would be a change!");
if(FadeFirstColor){
BlendR1 = random8(255);
BlendG1 = random8(255);
BlendB1 = random8(255);
}else{
BlendR2 = random8(255);
BlendG2 = random8(255);
BlendB2 = random8(255);
}
Serial.println(String(random8(255)));
Serial.println(String(random8(255)));
Serial.println(String(random8(255)));
FadeBlendRainbowSet = true;
}
FirstFade = false;
}
FadeFirstColor = !FadeFirstColor;
FadeBrightFlip = false;
}
if(max_brightness == cur_brightness){
FadeBrightFlip = true;
delay(10000);
}
if(FadeBrightFlip == true){
max_brightness = max_brightness - 1;
}else{
max_brightness = max_brightness + 1;
}
FastLED.setBrightness(max_brightness);
}
void blendCycle() {
uint8_t speed = beatsin8(6,0,255);
endclr = blend(CRGB( BlendR1, BlendG1, BlendB1), CRGB( BlendR2, BlendG2, BlendB2), speed);
midclr = blend(CRGB( BlendR2, BlendG2, BlendB2), CRGB( BlendR1, BlendG1, BlendB1), speed);
BlendFirstColor = true;
for( int i = 0; i < NUM_LEDS; i++) {
if(i%BlendGroup == 0){
if(BlendFirstColor == true){
BlendFirstColor = false;
}else{
BlendFirstColor = true;
}
}
if(BlendFirstColor == true){
leds[i]=endclr;
}else{
leds[i]=midclr;
}
}
}
void two_sin() {
thisdir ? thisphase += beatsin8(thisspeed, 2, 10) : thisphase -= beatsin8(thisspeed, 2, 10);
thatdir ? thatphase += beatsin8(thisspeed, 2, 10) : thatphase -= beatsin8(thatspeed, 2, 10);
thishue += thisrot; // Hue rotation is fun for thiswave.
thathue += thatrot; // It's also fun for thatwave.
for (int k=0; k<NUM_LEDS-1; k++) {
int thisbright = qsuba(cubicwave8((k*allfreq)+thisphase), thiscutoff); // qsub sets a minimum value called thiscutoff. If < thiscutoff, then bright = 0. Otherwise, bright = 128 (as defined in qsub)..
int thatbright = qsuba(cubicwave8((k*allfreq)+128+thatphase), thatcutoff); // This wave is 180 degrees out of phase (with the value of 128).
leds[k] = ColorFromPalette(thisPalette, thishue, thisbright, currentBlending);
leds[k] += ColorFromPalette(thatPalette, thathue, thatbright, currentBlending);
}
nscale8(leds,NUM_LEDS,fadeval);
} // two_sin()
// RainbowColors_p, RainbowStripeColors_p, OceanColors_p, CloudColors_p, ForestColors_p, and PartyColors_p.
void ChangeMe() {
uint8_t secondHand = (millis() / 1000) % 60; // Increase this if you want a longer demo.
static uint8_t lastSecond = 99; // Static variable, means it's only defined once. This is our 'debounce' variable.
if( lastSecond != secondHand) {
lastSecond = secondHand;
switch (secondHand) {
case 0: thisrot = 1; thatrot = 1; thisPalette=PartyColors_p; thatPalette=PartyColors_p; break;
case 5: thisrot = 0; thatdir = 1; thatspeed = -4; thisPalette=ForestColors_p; thatPalette=OceanColors_p; break;
case 10: thatrot = 0; thisPalette=PartyColors_p; thatPalette=RainbowColors_p; break;
case 15: allfreq = 16; thisdir = 1; thathue = 128; break;
case 20: thiscutoff = 96; thatcutoff = 240; break;
case 25: thiscutoff = 96; thatdir = 0; thatcutoff = 96; thisrot = 1; break;
case 30: thisspeed= -4; thisdir = 0; thatspeed= -4; break;
case 35: thiscutoff = 128; thatcutoff = 128; break;
case 40: thisspeed = 3; break;
case 45: thisspeed = 3; thatspeed = -3; break;
case 50: thisspeed = 2; thatcutoff = 96; thiscutoff = 224; thatspeed = 3; break;
case 55: resetvars(); break;
case 60: break;
}
}
} // ChangeMe()
void resetvars() { // Reset the variable back to the beginning.
thishue = 0; // You can change the starting hue value for the first wave.
thathue = 140; // You can change the starting hue for other wave.
thisrot = 1; // You can change how quickly the hue rotates for this wave. Currently 0.
thatrot = 1; // You can change how quickly the hue rotates for the other wave. Currently 0.
allsat = 255; // I like 'em fully saturated with colour.
thisdir = 0; // Change the direction of the first wave.
thatdir = 0; // Change the direction of the other wave.
alldir = 0; // You can change direction.
thisspeed = 4; // You can change the speed, and use negative values.
thatspeed = 4; // You can change the speed, and use negative values.
allfreq = 32; // You can change the frequency, thus overall width of bars.
thisphase = 0; // Phase change value gets calculated.
thatphase = 0; // Phase change value gets calculated.
thiscutoff = 192; // You can change the cutoff value to display this wave. Lower value = longer wave.
thatcutoff = 192; // You can change the cutoff value to display that wave. Lower value = longer wave.
thisdelay = 10; // You can change the delay. Also you can change the allspeed variable above.
fadeval = 192; // How quickly we fade.
} // resetvars()
void beatwave() {
uint8_t wave1 = beatsin8(9, 0, 255); // That's the same as beatsin8(9);
uint8_t wave2 = beatsin8(8, 0, 255);
uint8_t wave3 = beatsin8(7, 0, 255);
uint8_t wave4 = beatsin8(6, 0, 255);
for (int i=0; i<NUM_LEDS; i++) {
leds[i] = ColorFromPalette( currentPalette, i+wave1+wave2+wave3+wave4, 255, currentBlending);
}
} // beatwave()
void rainbow_march() { // The fill_rainbow call doesn't support brightness levels
rainbowHue++;
fill_rainbow(leds, NUM_LEDS, rainbowHue, rainbowDelta); // Use FastLED's fill_rainbow routine.
} // rainbow_march()
void rainbow_beat() {
uint8_t beatA = beatsin8(17, 0, 255); // Starting hue
uint8_t beatB = beatsin8(13, 0, 255);
fill_rainbow(leds, NUM_LEDS, (beatA+beatB)/2, 8); // Use FastLED's fill_rainbow routine.
} // rainbow_beat()
#define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
void nextPattern()
{
// add one to the current pattern number, and wrap around at the end
gCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE( gPatterns);
}
void rainbow_call()
{
homemade_method = false;
rainbowMarchOn = false;
rainbowBeatOn = false;
beatWaveOn = false;
twoSinPalOn = false;
FadeCycleOn = false;
BlendCycleOn = false;
gCurrentPatternNumber = (1 - 1) % ARRAY_SIZE( gPatterns);
// FastLED's built-in rainbow generator
}
void rainbowWithGlitter_call()
{
homemade_method = false;
rainbowMarchOn = false;
rainbowBeatOn = false;
beatWaveOn = false;
twoSinPalOn = false;
FadeCycleOn = false;
BlendCycleOn = false;
gCurrentPatternNumber = (2 - 1) % ARRAY_SIZE( gPatterns);
// built-in FastLED rainbow, plus some random sparkly glitter
}
void confetti_call()
{
homemade_method = false;
rainbowMarchOn = false;
rainbowBeatOn = false;
beatWaveOn = false;
twoSinPalOn = false;
FadeCycleOn = false;
BlendCycleOn = false;
gCurrentPatternNumber = (3 - 1) % ARRAY_SIZE( gPatterns);
// random colored speckles that blink in and fade smoothly
}
void confetti_color_call()
{
homemade_method = false;
rainbowMarchOn = false;
rainbowBeatOn = false;
beatWaveOn = false;
twoSinPalOn = false;
FadeCycleOn = false;
BlendCycleOn = false;
gCurrentPatternNumber = (7 - 1) % ARRAY_SIZE( gPatterns);
// random colored speckles that blink in and fade smoothly
}
void sinelon_call()
{
homemade_method = false;
rainbowMarchOn = false;
rainbowBeatOn = false;
beatWaveOn = false;
twoSinPalOn = false;
FadeCycleOn = false;
BlendCycleOn = false;
gCurrentPatternNumber = (4 - 1) % ARRAY_SIZE( gPatterns);
// a colored dot sweeping back and forth, with fading trails
}
void bpm_call()
{
homemade_method = false;
rainbowMarchOn = false;
rainbowBeatOn = false;
beatWaveOn = false;
twoSinPalOn = false;
FadeCycleOn = false;
BlendCycleOn = false;
gCurrentPatternNumber = (5 - 1) % ARRAY_SIZE( gPatterns);
// built-in FastLED rainbow, plus some random sparkly glitter
}
void juggle_call()
{
homemade_method = false;
rainbowMarchOn = false;
rainbowBeatOn = false;
beatWaveOn = false;
twoSinPalOn = false;
FadeCycleOn = false;
BlendCycleOn = false;
gCurrentPatternNumber = (6 - 1) % ARRAY_SIZE( gPatterns);
// a colored dot sweeping back and forth, with fading trails
}
void next_call()
{
homemade_method = false;
rainbowMarchOn = false;
rainbowBeatOn = false;
beatWaveOn = false;
twoSinPalOn = false;
FadeCycleOn = false;
BlendCycleOn = false;
nextPattern();
}
void rainbow()
{
// FastLED's built-in rainbow generator
fill_rainbow( leds, NUM_LEDS, gHue, 7);
}
void rainbowWithGlitter()
{
// built-in FastLED rainbow, plus some random sparkly glitter
rainbow();
addGlitter(80);
}
void addGlitter( fract8 chanceOfGlitter)
{
if ( random8() < chanceOfGlitter) {
leds[ random16(NUM_LEDS) ] += CRGB::White;
}
}
void confetti()
{
// random colored speckles that blink in and fade smoothly
fadeToBlackBy( leds, NUM_LEDS, 20);
int pos = random16(NUM_LEDS);
leds[pos] += CHSV( gHue + random8(64), 200, 255);
}
void confettiColor(){
for (int k = 0; k < NUM_LEDS; k++) {
leds[k].setRGB(r, g, b);
}
addGlitter(1000 / FRAMES_PER_SECOND);
int pos = random16(NUM_LEDS);
leds[pos] += CHSV( gHue + random8(64), 200, 255);
}
void sinelon()
{
// a colored dot sweeping back and forth, with fading trails
fadeToBlackBy( leds, NUM_LEDS, 20);
int pos = beatsin16( 13, 0, NUM_LEDS - 1 );
leds[pos] += CHSV( gHue, 255, 192);
}
void bpm()
{
// colored stripes pulsing at a defined Beats-Per-Minute (BPM)
CRGBPalette16 palette = PartyColors_p;
uint8_t beat = beatsin8( BeatsPerMinute, 64, 255);
for ( int i = 0; i < NUM_LEDS; i++) { //9948
leds[i] = ColorFromPalette(palette, gHue + (i * 2), beat - gHue + (i * 10));
}
}
void juggle() {
// eight colored dots, weaving in and out of sync with each other
fadeToBlackBy( leds, NUM_LEDS, 20);
byte dothue = 0;
for ( int i = 0; i < 8; i++) {
leds[beatsin16( i + 7, 0, NUM_LEDS - 1 )] |= CHSV(dothue, 200, 255);
dothue += 32;
}
}
//LED METHODS TO RUN END!