-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTeensy_MIDI_test.ino
1101 lines (1030 loc) · 30.6 KB
/
Teensy_MIDI_test.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
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
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <Arduino.h>
#include <MIDI.h>
#include <FastLED.h>
#include <RotaryEncoder.h>
// DECLERATION OF FUNCTIONS
void myNoteOn(byte channel, byte pitch, byte velocity);
void modechange();
void editMode();
void colorEdit();
void saveSetting();
void bassLed();
void snareLed();
void tom1Led();
void tom2Led();
void tom3Led();
void hihatLed();
void crashLed();
void rideLed();
void patterns();
void nextPattern();
void prevPattern();
void setFade();
void rainbow();
void rainbowWithGlitter();
void confetti();
void sinelon();
void juggle();
void bpm();
// ENCODER SETTING
#define PIN_IN1 14
#define PIN_IN2 15
#define modeButton 16
// PINS FOR LED STRIPS
#define TOM1PIN 8
#define TOM2PIN 7
#define TOM3PIN 10
#define SNAREPIN 12
#define BASSPIN 11
#define HIHATPIN 13
#define CRASHPIN 6
#define RIDEPIN 9
// NUMBER OF LEDS PER PAD
#define TOM1LEDS 34
#define TOM2LEDS 34
#define TOM3LEDS 34
#define SNARELEDS 54
#define BASSLEDS 67
#define HIHATLEDS 30
#define CRASHLEDS 37
#define RIDELEDS 37
#define NUM_LEDS TOM1LEDS + TOM2LEDS + TOM3LEDS + SNARELEDS + BASSLEDS + HIHATLEDS + CRASHLEDS + RIDELEDS // TOTAL LEDS
#define NUM_STRIPS 8 // TOTAL STRIPS
// PATTERN SPECIFIC SETTINGS
#define FRAMES_PER_SECOND 120
#define SPARKING 190
#define COOLING 55 // TOTAL STRIPS
//CREATE MIDI AND ENCODER
MIDI_CREATE_INSTANCE(HardwareSerial, Serial5, MIDI);
RotaryEncoder encoder(PIN_IN1, PIN_IN2, RotaryEncoder::LatchMode::TWO03);
// VARIABLES AND DEFAULTS
byte brightness = 100;
byte minBrightness = 0;
byte mintom1Brightness = 0;
byte mintom2Brightness = 0;
byte mintom3Brightness = 0;
byte minsnareBrightness = 0;
byte minbassBrightness = 0;
byte minhihatBrightness = 0;
byte mincrashBrightness = 0;
byte minrideBrightness = 0;
byte bassSpeed = 2;
byte snareSpeed = 2;
byte tom1Speed = 1;
byte tom2Speed = 1;
byte tom3Speed = 1;
byte hiHatSpeed = 6;
byte crashSpeed = 2;
byte rideSpeed = 2;
byte tom1Color = 45;
byte tom2Color = 160;
byte tom3Color = 95;
byte snareColor = 0;
byte bassColor = 210;
byte hihatColor = 45;
byte crashColor = 160;
byte rideColor = 95;
byte tom1Brightness = 255;
byte tom2Brightness = 255;
byte tom3Brightness = 255;
byte snareBrightness = 255;
byte bassBrightness = 255;
byte hihatBrightness = 255;
byte crashBrightness = 255;
byte rideBrightness = 255;
//DEBUG TESTING
bool printed = false;
byte setMode = 0;
byte padHit = 0;
byte setEdit = 0;
static byte color = 0;
byte speedSet = 0;
// CREATE LED STRIPS
CRGB tom1strip[TOM1LEDS];
CRGB tom2strip[TOM1LEDS];
CRGB tom3strip[TOM1LEDS];
CRGB snarestrip[SNARELEDS];
CRGB bassstrip[BASSLEDS];
CRGB hihatstrip[HIHATLEDS];
CRGB crashstrip[CRASHLEDS];
CRGB ridestrip[RIDELEDS];
CRGB leds[NUM_LEDS];
CLEDController *controllers[NUM_STRIPS];
void setup()
{
Serial.begin(115200);
//Serial5.begin(31250);
Serial.println("I am ALIVE and ready to send MIDI Stuff");
pinMode(modeButton, INPUT_PULLUP);
FastLED.addLeds<1, WS2812B, TOM1PIN, GRB>(tom1strip, TOM1LEDS);
FastLED.addLeds<1, WS2812B, TOM2PIN, GRB>(tom2strip, TOM2LEDS);
FastLED.addLeds<1, WS2812B, TOM3PIN, GRB>(tom3strip, TOM3LEDS);
FastLED.addLeds<1, WS2812B, SNAREPIN, GRB>(snarestrip, SNARELEDS);
FastLED.addLeds<1, WS2812B, BASSPIN, GRB>(bassstrip, BASSLEDS);
FastLED.addLeds<1, WS2812B, HIHATPIN, GRB>(hihatstrip, HIHATLEDS);
FastLED.addLeds<1, WS2812B, CRASHPIN, GRB>(crashstrip, CRASHLEDS);
FastLED.addLeds<1, WS2812B, RIDEPIN, GRB>(ridestrip, RIDELEDS);
Serial.println(" Testing Strips :::::: They should flash 3 times. ");
delay(500);
fill_solid(tom1strip, TOM1LEDS, CHSV(tom1Color, 255, tom1Brightness));
fill_solid(tom2strip, TOM2LEDS, CHSV(tom2Color, 255, tom2Brightness));
fill_solid(tom3strip, TOM3LEDS, CHSV(tom3Color, 255, tom3Brightness));
fill_solid(snarestrip, SNARELEDS, CHSV(snareColor, 255, snareBrightness));
fill_solid(bassstrip, BASSLEDS, CHSV(bassColor, 255, bassBrightness));
fill_solid(hihatstrip, HIHATLEDS, CHSV(hihatColor, 255, hihatBrightness));
fill_solid(crashstrip, CRASHLEDS, CHSV(crashColor, 255, crashBrightness));
fill_solid(ridestrip, RIDELEDS, CHSV(rideColor, 255, rideBrightness));
FastLED.show(50);
Serial.println(" FLASH 1");
delay(500);
FastLED.clear();
FastLED.show();
delay(500);
fill_solid(tom1strip, TOM1LEDS, CHSV(tom1Color, 255, tom1Brightness));
fill_solid(tom2strip, TOM2LEDS, CHSV(tom2Color, 255, tom2Brightness));
fill_solid(tom3strip, TOM3LEDS, CHSV(tom3Color, 255, tom3Brightness));
fill_solid(snarestrip, SNARELEDS, CHSV(snareColor, 255, snareBrightness));
fill_solid(bassstrip, BASSLEDS, CHSV(bassColor, 255, bassBrightness));
fill_solid(hihatstrip, HIHATLEDS, CHSV(hihatColor, 255, hihatBrightness));
fill_solid(crashstrip, CRASHLEDS, CHSV(crashColor, 255, crashBrightness));
fill_solid(ridestrip, RIDELEDS, CHSV(rideColor, 255, rideBrightness));
FastLED.show(50);
Serial.println(" FLASH 2");
delay(500);
FastLED.clear();
FastLED.show();
delay(500);
fill_solid(tom1strip, TOM1LEDS, CHSV(tom1Color, 255, tom1Brightness));
fill_solid(tom2strip, TOM2LEDS, CHSV(tom2Color, 255, tom2Brightness));
fill_solid(tom3strip, TOM3LEDS, CHSV(tom3Color, 255, tom3Brightness));
fill_solid(snarestrip, SNARELEDS, CHSV(snareColor, 255, snareBrightness));
fill_solid(bassstrip, BASSLEDS, CHSV(bassColor, 255, bassBrightness));
fill_solid(hihatstrip, HIHATLEDS, CHSV(hihatColor, 255, hihatBrightness));
fill_solid(crashstrip, CRASHLEDS, CHSV(crashColor, 255, crashBrightness));
fill_solid(ridestrip, RIDELEDS, CHSV(rideColor, 255, rideBrightness));
FastLED.show(50);
Serial.println(" FLASH 3");
Serial.println("NEW VERSION WITH ENCODER AND HARDWARE MIDI INPUT 6.2");
MIDI.setHandleNoteOn(myNoteOn);
MIDI.begin(10);
//usbMIDI.setHandleNoteOn(myNoteOn);
attachInterrupt(digitalPinToInterrupt(modeButton), modechange, CHANGE); // Mode Change Interrupt
}
// PATTERN SETTING
typedef void (*SimplePatternList[])();
SimplePatternList gPatterns = {
rainbow,
rainbowWithGlitter,
confetti,
sinelon,
juggle,
bpm,
};
uint8_t gCurrentPatternNumber = 0; // Index number of which pattern is current
uint8_t gHue = 0; // rotating "base color" used by many of the patterns
void loop()
{
// The handler functions are called when usbMIDI reads data. They
// will not be called automatically. You must call usbMIDI.read()
// regularly from loop() for usbMIDI to actually read incoming
// data and run the handler functions as messages arrive.
//usbMIDI.read();
MIDI.read();
encoder.tick();
if (setMode == 1)
{
switch (setEdit)
{
case 0:
editMode();
break;
case 2:
colorEdit();
break;
case 3:
setFade();
}
}
if (setMode == 2)
{
minBrightness = 10;
patterns();
}
EVERY_N_MILLISECONDS(20)
{
if (tom1Brightness > minBrightness)
{
tom1Brightness -= (tom1Speed);
FastLED[0].showLeds(tom1Brightness);
}
if (tom2Brightness > minBrightness)
{
tom2Brightness -= (tom2Speed);
FastLED[1].showLeds(tom2Brightness);
}
if (tom3Brightness > minBrightness)
{
tom3Brightness -= (tom3Speed);
FastLED[2].showLeds(tom3Brightness);
}
if (snareBrightness > minBrightness)
{
snareBrightness -= (snareSpeed);
FastLED[3].showLeds(snareBrightness);
}
if (bassBrightness > minBrightness)
{
bassBrightness -= (bassSpeed);
FastLED[4].showLeds(bassBrightness);
}
if (hihatBrightness > minBrightness)
{
hihatBrightness -= (hiHatSpeed);
FastLED[5].showLeds(hihatBrightness);
}
if (crashBrightness > minBrightness)
{
crashBrightness -= (crashSpeed);
FastLED[6].showLeds(crashBrightness);
}
if (rideBrightness > minBrightness)
{
rideBrightness -= (rideSpeed);
FastLED[7].showLeds(rideBrightness);
}
}
}
void patterns()
{
RotaryEncoder::Direction dir = encoder.getDirection();
if (dir == RotaryEncoder::Direction::CLOCKWISE)
{
nextPattern();
Serial.println(gCurrentPatternNumber);
}
if (dir == RotaryEncoder::Direction::COUNTERCLOCKWISE)
{
prevPattern();
Serial.println(gCurrentPatternNumber);
}
// Call the current pattern function once, updating the 'leds' array
gPatterns[gCurrentPatternNumber]();
FastLED[0].showLeds(tom1Brightness);
FastLED[1].showLeds(tom2Brightness);
FastLED[2].showLeds(tom3Brightness);
FastLED[3].showLeds(snareBrightness);
FastLED[4].showLeds(bassBrightness);
FastLED[5].showLeds(hihatBrightness);
FastLED[6].showLeds(crashBrightness);
FastLED[7].showLeds(rideBrightness);
// insert a delay to keep the framerate modest
//FastLED.delay(1000 / FRAMES_PER_SECOND);
// do some periodic updates
EVERY_N_MILLISECONDS(20);
{
gHue++; // slowly cycle the "base color" through the rainbow
}
}
#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 prevPattern()
{
gCurrentPatternNumber = (gCurrentPatternNumber - 1);
if (gCurrentPatternNumber > ARRAY_SIZE(gPatterns))
{
gCurrentPatternNumber = ARRAY_SIZE(gPatterns) - 1;
}
}
void rainbow()
{
// FastLED's built-in rainbow generator
fill_rainbow(tom1strip, TOM1LEDS, gHue, 7);
fill_rainbow(tom2strip, TOM2LEDS, gHue, 7);
fill_rainbow(tom3strip, TOM3LEDS, gHue, 7);
fill_rainbow(snarestrip, SNARELEDS, gHue, 7);
fill_rainbow(bassstrip, BASSLEDS, gHue, 7);
fill_rainbow(hihatstrip, HIHATLEDS, gHue, 7);
fill_rainbow(crashstrip, CRASHLEDS, gHue, 7);
fill_rainbow(ridestrip, RIDELEDS, gHue, 7);
}
void rainbowWithGlitter()
{
// built-in FastLED rainbow, plus some random sparkly glitter
rainbow();
addGlitter(80);
}
void addGlitter(fract8 chanceOfGlitter)
{
if (random8() < chanceOfGlitter)
{
tom1strip[random16(TOM1LEDS)] += CRGB::White;
tom2strip[random16(TOM2LEDS)] += CRGB::White;
tom3strip[random16(TOM3LEDS)] += CRGB::White;
snarestrip[random16(SNARELEDS)] += CRGB::White;
bassstrip[random16(BASSLEDS)] += CRGB::White;
hihatstrip[random16(HIHATLEDS)] += CRGB::White;
crashstrip[random16(CRASHLEDS)] += CRGB::White;
ridestrip[random16(RIDELEDS)] += CRGB::White;
}
}
void confetti()
{
// random colored speckles that blink in and fade smoothly
fadeToBlackBy(tom1strip, TOM1LEDS, 10);
fadeToBlackBy(tom2strip, TOM2LEDS, 10);
fadeToBlackBy(tom3strip, TOM3LEDS, 10);
fadeToBlackBy(snarestrip, SNARELEDS, 10);
fadeToBlackBy(bassstrip, BASSLEDS, 10);
fadeToBlackBy(hihatstrip, HIHATLEDS, 10);
fadeToBlackBy(crashstrip, CRASHLEDS, 10);
fadeToBlackBy(ridestrip, RIDELEDS, 10);
int pos1 = random16(TOM1LEDS);
int pos2 = random16(TOM2LEDS);
int pos3 = random16(TOM3LEDS);
int pos4 = random16(SNARELEDS);
int pos5 = random16(BASSLEDS);
int pos6 = random16(HIHATLEDS);
int pos7 = random16(CRASHLEDS);
int pos8 = random16(RIDELEDS);
tom1strip[pos1] += CHSV(gHue + random8(64), 200, tom1Brightness);
tom2strip[pos2] += CHSV(gHue + random8(64), 200, tom2Brightness);
tom3strip[pos3] += CHSV(gHue + random8(64), 200, tom3Brightness);
snarestrip[pos4] += CHSV(gHue + random8(64), 200, snareBrightness);
bassstrip[pos5] += CHSV(gHue + random8(64), 200, bassBrightness);
hihatstrip[pos6] += CHSV(gHue + random8(64), 200, hihatBrightness);
crashstrip[pos7] += CHSV(gHue + random8(64), 200, crashBrightness);
ridestrip[pos8] += CHSV(gHue + random8(64), 200, rideBrightness);
}
void sinelon()
{
// a colored dot sweeping back and forth, with fading trails
fadeToBlackBy(tom1strip, TOM1LEDS, 20);
fadeToBlackBy(tom2strip, TOM2LEDS, 20);
fadeToBlackBy(tom3strip, TOM3LEDS, 20);
fadeToBlackBy(snarestrip, SNARELEDS, 20);
fadeToBlackBy(bassstrip, BASSLEDS, 20);
fadeToBlackBy(hihatstrip, HIHATLEDS, 20);
fadeToBlackBy(crashstrip, CRASHLEDS, 20);
fadeToBlackBy(ridestrip, RIDELEDS, 20);
int pos1 = beatsin16(13, 0, TOM1LEDS - 1);
int pos2 = beatsin16(13, 0, TOM2LEDS - 1);
int pos3 = beatsin16(13, 0, TOM3LEDS - 1);
int pos4 = beatsin16(13, 0, SNARELEDS - 1);
int pos5 = beatsin16(13, 0, BASSLEDS - 1);
int pos6 = beatsin16(13, 0, HIHATLEDS - 1);
int pos7 = beatsin16(13, 0, CRASHLEDS - 1);
int pos8 = beatsin16(13, 0, RIDELEDS - 1);
tom1strip[pos1] += CHSV(gHue, 255, 192);
tom2strip[pos2] += CHSV(gHue, 255, 192);
tom3strip[pos3] += CHSV(gHue, 255, 192);
snarestrip[pos4] += CHSV(gHue, 255, 192);
bassstrip[pos5] += CHSV(gHue, 255, 192);
hihatstrip[pos6] += CHSV(gHue, 255, 192);
crashstrip[pos7] += CHSV(gHue, 255, 192);
ridestrip[pos8] += CHSV(gHue, 255, 192);
}
void bpm()
{
// colored stripes pulsing at a defined Beats-Per-Minute (BPM)
uint8_t BeatsPerMinute = 62;
CRGBPalette16 palette = PartyColors_p;
uint8_t beat = beatsin8(BeatsPerMinute, 64, 255);
for (int i = 0; i < TOM1LEDS; i++)
{ //9948
tom1strip[i] = ColorFromPalette(palette, gHue + (i * 2), beat - gHue + (i * 10));
tom2strip[i] = ColorFromPalette(palette, gHue + (i * 2), beat - gHue + (i * 10));
tom3strip[i] = ColorFromPalette(palette, gHue + (i * 2), beat - gHue + (i * 10));
}
for (int i = 0; i < SNARELEDS; i++)
{ //9948
snarestrip[i] = ColorFromPalette(palette, gHue + (i * 2), beat - gHue + (i * 10));
}
for (int i = 0; i < BASSLEDS; i++)
{ //9948
bassstrip[i] = ColorFromPalette(palette, gHue + (i * 2), beat - gHue + (i * 10));
}
for (int i = 0; i < HIHATLEDS; i++)
{ //9948
hihatstrip[i] = ColorFromPalette(palette, gHue + (i * 2), beat - gHue + (i * 10));
}
for (int i = 0; i < CRASHLEDS; i++)
{ //9948
crashstrip[i] = ColorFromPalette(palette, gHue + (i * 2), beat - gHue + (i * 10));
}
for (int i = 0; i < RIDELEDS; i++)
{ //9948
ridestrip[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(tom1strip, TOM1LEDS, 20);
fadeToBlackBy(tom2strip, TOM2LEDS, 20);
fadeToBlackBy(tom3strip, TOM3LEDS, 20);
fadeToBlackBy(snarestrip, SNARELEDS, 20);
fadeToBlackBy(bassstrip, BASSLEDS, 20);
fadeToBlackBy(hihatstrip, HIHATLEDS, 20);
fadeToBlackBy(crashstrip, CRASHLEDS, 20);
fadeToBlackBy(ridestrip, RIDELEDS, 20);
byte dothue = 0;
for (int i = 0; i < 8; i++)
{
tom1strip[beatsin16(i + 7, 0, TOM1LEDS - 1)] |= CHSV(dothue, 200, tom1Brightness);
tom2strip[beatsin16(i + 7, 0, TOM2LEDS - 1)] |= CHSV(dothue, 200, tom2Brightness);
tom3strip[beatsin16(i + 7, 0, TOM3LEDS - 1)] |= CHSV(dothue, 200, tom3Brightness);
snarestrip[beatsin16(i + 7, 0, SNARELEDS - 1)] |= CHSV(dothue, 200, snareBrightness);
bassstrip[beatsin16(i + 7, 0, BASSLEDS - 1)] |= CHSV(dothue, 200, bassBrightness);
hihatstrip[beatsin16(i + 7, 0, HIHATLEDS - 1)] |= CHSV(dothue, 200, hihatBrightness);
crashstrip[beatsin16(i + 7, 0, CRASHLEDS - 1)] |= CHSV(dothue, 200, crashBrightness);
ridestrip[beatsin16(i + 7, 0, RIDELEDS - 1)] |= CHSV(dothue, 200, rideBrightness);
dothue += 32;
}
}
void myNoteOn(byte channel, byte pitch, byte velocity)
{
// When using MIDIx4 or MIDIx16, usbMIDI.getCable() can be used
// to read which of the virtual MIDI cables received this message.
brightness = map(velocity, 1, 127, 0, 255);
switch (pitch)
{
case 36: //bass
if ((padHit == 1) && (setEdit == 2))
{
Serial.println("====== SET FADE SPEED ======");
encoder.setPosition(bassSpeed);
setEdit = 3;
printed = false;
FastLED.clear();
FastLED.show();
break;
}
if ((padHit == 1) && (setEdit == 3))
{
Serial.println("====== SETTING SAVED ======");
setEdit = 0;
printed = false;
FastLED.clear();
FastLED.show();
padHit = 0;
break;
}
padHit = 1;
if (setMode == 2) {
bassBrightness = brightness;
break;
}
bassBrightness = brightness;
fill_solid(bassstrip, BASSLEDS, CHSV(bassColor, 255, bassBrightness));
FastLED[4].showLeds();
break;
case 38: //SNARE
case 40: //SNARE RIM
case 37: //SNARE X-stick
if ((padHit == 2) && (setEdit == 2))
{
Serial.println("====== SET FADE SPEED ======");
encoder.setPosition(snareSpeed);
setEdit = 3;
printed = false;
FastLED.clear();
FastLED.show();
break;
}
if ((padHit == 2) && (setEdit == 3))
{
Serial.println("====== SETTING SAVED ======");
setEdit = 0;
printed = false;
FastLED.clear();
FastLED.show();
padHit = 0;
break;
}
padHit = 2;
if (setMode == 2) {
snareBrightness = brightness;
break;
}
snareBrightness = brightness;
fill_solid(snarestrip, SNARELEDS, CHSV(snareColor, 255, snareBrightness));
FastLED[3].showLeds();
break;
case 48: //TOM 1 HEAD
case 50: //TOM 1 RIM
if ((padHit == 3) && (setEdit == 2))
{
Serial.println("====== SET FADE SPEED ======");
encoder.setPosition(tom1Speed);
setEdit = 3;
printed = false;
FastLED.clear();
FastLED.show();
break;
}
if ((padHit == 3) && (setEdit == 3))
{
Serial.println("====== SETTING SAVED ======");
setEdit = 0;
printed = false;
FastLED.clear();
FastLED.show();
padHit = 0;
break;
}
padHit = 3;
if (setMode == 2) {
tom1Brightness = brightness;
break;
}
tom1Brightness = brightness;
fill_solid(tom1strip, TOM1LEDS, CHSV(tom1Color, 255, tom1Brightness));
FastLED[0].showLeds();
break;
case 45: //TOM 2 HEAD
case 47: //TOM 2 RIM
if ((padHit == 4) && (setEdit == 2))
{
Serial.println("====== SET FADE SPEED ======");
encoder.setPosition(tom2Speed);
setEdit = 3;
printed = false;
FastLED.clear();
FastLED.show();
break;
}
if ((padHit == 4) && (setEdit == 3))
{
Serial.println("====== SETTING SAVED ======");
setEdit = 0;
printed = false;
FastLED.clear();
FastLED.show();
padHit = 0;
break;
}
padHit = 4;
if (setMode == 2) {
tom2Brightness = brightness;
break;
}
tom2Brightness = brightness;
fill_solid(tom2strip, TOM2LEDS, CHSV(tom2Color, 255, tom2Brightness));
FastLED[1].showLeds();
break;
case 43: //TOM 3 HEAD
case 58: //TOM 3 RIM
if ((padHit == 5) && (setEdit == 2))
{
Serial.println("====== SET FADE SPEED ======");
encoder.setPosition(tom3Speed);
setEdit = 3;
printed = false;
FastLED.clear();
FastLED.show();
break;
}
if ((padHit == 5) && (setEdit == 3))
{
Serial.println("====== SETTING SAVED ======");
setEdit = 0;
printed = false;
FastLED.clear();
FastLED.show();
padHit = 0 ;
break;
;
}
padHit = 5;
if (setMode == 2) {
tom3Brightness = brightness;
break;
}
tom3Brightness = brightness;
fill_solid(tom3strip, TOM3LEDS, CHSV(tom3Color, 255, tom3Brightness));
FastLED[2].showLeds();
break;
case 46: //HH OPEN BOW
case 26: //HH OPEN EDGE
case 42: //HH CLOSED BOW
case 22: //HH CLOSED EDGE
case 44: // HH PEDAL
if ((padHit == 6) && (setEdit == 2))
{
Serial.println("====== SET FADE SPEED ======");
encoder.setPosition(hiHatSpeed);
setEdit = 3;
printed = false;
FastLED.clear();
FastLED.show();
break;
}
if ((padHit == 6) && (setEdit == 3))
{
Serial.println("====== SETTING SAVED ======");
setEdit = 0;
printed = false;
FastLED.clear();
FastLED.show();
padHit = 0;
break;
}
padHit = 6;
if (setMode == 2) {
hihatBrightness = brightness;
break;
}
hihatBrightness = brightness;
fill_solid(hihatstrip, HIHATLEDS, CHSV(hihatColor, 255, hihatBrightness));
FastLED[5].showLeds();
break;
case 49: // CRASH 1 BOW
case 55: // CRASH 1 EDGE
if ((padHit == 7) && (setEdit == 2))
{
Serial.println("====== SET FADE SPEED ======");
encoder.setPosition(crashSpeed);
setEdit = 3;
printed = false;
FastLED.clear();
FastLED.show();
break;
}
if ((padHit == 7) && (setEdit == 3))
{
Serial.println("====== SETTING SAVED ======");
setEdit = 0;
printed = false;
FastLED.clear();
FastLED.show();
padHit = 0;
break;
}
padHit = 7;
if (setMode == 2) {
crashBrightness = brightness;
break;
}
crashBrightness = brightness;
fill_solid(crashstrip, CRASHLEDS, CHSV(crashColor, 255, crashBrightness));
FastLED[6].showLeds();
break;
case 51: //RIDE BOW
case 59: //RIDE EDGE
if ((padHit == 8) && (setEdit == 2))
{
Serial.println("====== SET FADE SPEED ======");
encoder.setPosition(rideSpeed);
setEdit = 3;
printed = false;
FastLED.clear();
FastLED.show();
break;
}
if ((padHit == 8) && (setEdit == 3))
{
Serial.println("====== SETTING SAVED ======");
setEdit = 0;
printed = false;
FastLED.clear();
FastLED.show();
padHit = 0;
break;
}
padHit = 8;
if (setMode == 2) {
rideBrightness = brightness;
break;
}
rideBrightness = brightness;
fill_solid(ridestrip, RIDELEDS, CHSV(rideColor, 255, rideBrightness));
FastLED[7].showLeds();
break;
}
}
void editMode()
{
if (padHit == 0)
{
if (printed == false)
{
Serial.println("======== EDIT MODE ENABLED ========");
Serial.println("======== HIT PAD TO SELECT ========");
delay(50);
printed = true;
}
}
if (padHit != 0)
{
//setMode = 0;
setEdit = 2;
printed = false;
switch (padHit)
{
case 1:
Serial.println("======== BASS ======== ");
Serial.println("======== SELECTED ======== ");
encoder.setPosition(bassColor);
delay(1000);
break;
case 2:
Serial.println("======== SNARE ======== ");
Serial.println("======== SELECTED ======== ");
encoder.setPosition(snareColor);
break;
case 3:
Serial.println("======== TOM 1 ======== ");
Serial.println("======== SELECTED ======== ");
encoder.setPosition(tom1Color);
break;
case 4:
Serial.println("======== TOM 2 ======== ");
Serial.println("======== SELECTED ======== ");
encoder.setPosition(tom2Color);
break;
case 5:
Serial.println("======== TOM 3 ======== ");
Serial.println("======== SELECTED ======== ");
encoder.setPosition(tom3Color);
break;
case 6:
Serial.println("======== HI HAT ======== ");
Serial.println("======== SELECTED ======== ");
encoder.setPosition(hihatColor);
break;
case 7:
Serial.println("======== CRASH ======== ");
Serial.println("======== SELECTED ======== ");
encoder.setPosition(crashColor);
break;
case 8:
Serial.println("======== RIDE ======== ");
Serial.println("======== SELECTED ======== ");
encoder.setPosition(rideColor);
break;
}
}
}
void colorEdit()
{
if (printed == false)
{
Serial.print("======== Select Color for ");
Serial.print(padHit);
Serial.println(" ========");
printed = true;
}
static int pos = 0;
byte newPos = encoder.getPosition();
if (pos != newPos)
{
pos = newPos;
color = newPos;
} // if
Serial.println(color);
// COLOR ENCODER BUTTON TO SAVE SETTING
if ((color >= 0) && (color <= 21))
{
Serial.println("RED");
}
if ((color >= 22) && (color <= 64))
{
Serial.println("YELLOW");
}
if ((color >= 65) && (color <= 106))
{
Serial.println("GREEN");
}
if ((color >= 107) && (color <= 148))
{
Serial.println("AQUA");
}
if ((color >= 149) && (color <= 191))
{
Serial.println("BLUE");
}
if ((color >= 192) && (color <= 233))
{
Serial.println("BLUE");
}
if ((color >= 234) && (color <= 255))
{
Serial.println("RED");
}
// THIS THEN ALOCATES THE COLOR TO THE PAD THAT HAS BEEN SELECTED
switch (padHit)
{
case 1:
bassColor = color;
bassBrightness = 255;
fill_solid(bassstrip, BASSLEDS, CHSV(bassColor, 255, bassBrightness));
FastLED.show();
break;
case 2:
snareColor = color;
snareBrightness = 255;
fill_solid(snarestrip, SNARELEDS, CHSV(snareColor, 255, snareBrightness));
FastLED.show();
break;
case 3:
tom1Color = color;
tom1Brightness = 255;
fill_solid(tom1strip, TOM1LEDS, CHSV(tom1Color, 255, tom1Brightness));
FastLED.show();
break;
case 4:
tom2Color = color;
tom2Brightness = 255;
fill_solid(tom2strip, TOM2LEDS, CHSV(tom2Color, 255, tom2Brightness));
FastLED.show();
break;
case 5:
tom3Color = color;
tom1Brightness = 255;
fill_solid(tom3strip, TOM3LEDS, CHSV(tom3Color, 255, tom3Brightness));
FastLED.show();
break;
case 6:
hihatColor = color;
hihatBrightness = 255;
fill_solid(hihatstrip, HIHATLEDS, CHSV(hihatColor, 255, hihatBrightness));
FastLED.show();
break;
case 7:
crashColor = color;
crashBrightness = 255;
fill_solid(crashstrip, CRASHLEDS, CHSV(crashColor, 255, crashBrightness));
FastLED.show();
break;
case 8:
rideColor = color;
rideBrightness = 255;
fill_solid(ridestrip, RIDELEDS, CHSV(rideColor, 255, rideBrightness));
FastLED.show();
break;
}
}
void setFade()
{
if (printed == false)
{
Serial.print("======== Select Fade for ");
Serial.print(padHit);
Serial.println(" ========");
printed = true;
}
static int pos = 0;
byte newPos = encoder.getPosition();
if (pos != newPos)
{
pos = newPos;
speedSet = newPos;
} // if
Serial.println(speedSet);
// COLOR ENCODER BUTTON TO SAVE SETTING
// THIS THEN ALOCATES THE COLOR TO THE PAD THAT HAS BEEN SELECTED
switch (padHit)
{
case 1:
bassSpeed = speedSet;
if (bassBrightness <= 0)
{
bassBrightness = 255;
//delay (20);
}
fill_solid(bassstrip, BASSLEDS, CHSV(bassColor, 255, bassBrightness));
FastLED.show();
break;
case 2:
snareSpeed = speedSet;
if (snareBrightness <= 0)
{
snareBrightness = 255;
}
fill_solid(snarestrip, SNARELEDS, CHSV(snareColor, 255, snareBrightness));
FastLED.show();
break;
case 3:
tom1Speed = speedSet;
if (tom1Brightness <= 0)
{
tom1Brightness = 255;
}
fill_solid(tom1strip, TOM1LEDS, CHSV(tom1Color, 255, tom1Brightness));
FastLED.show();
break;
case 4:
tom2Speed = speedSet;
if (tom2Brightness <= 0)
{
tom2Brightness = 255;
}
fill_solid(tom2strip, TOM2LEDS, CHSV(tom2Color, 255, tom2Brightness));
FastLED.show();
break;
case 5:
tom3Speed = speedSet;
if (tom3Brightness <= 0)
{
tom3Brightness = 255;