forked from macetech/RGBShades
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.h
119 lines (92 loc) · 2.81 KB
/
utils.h
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
// Assorted useful functions and variables
boolean effectInit = false; // indicates if a pattern has been recently switched
uint16_t effectDelay = 0; // time between automatic effect changes
unsigned long effectMillis = 0; // store the time of last effect function run
unsigned long cycleMillis = 0; // store the time of last effect change
unsigned long currentMillis; // store current loop's millis value
unsigned long hueMillis; // store time of last hue change
byte currentEffect = 0; // index to the currently running effect
boolean autoCycle = true; // flag for automatic effect changes
CRGBPalette16 currentPalette(RainbowColors_p); // global pallete storage
typedef void (*functionList)(); // definition for list of effect function pointers
#define numEffects (sizeof(effectList) / sizeof(effectList[0]))
// Increment the global hue value for functions that use it
byte cycleHue = 0;
byte cycleHueCount = 0;
void hueCycle(byte incr) {
cycleHueCount = 0;
cycleHue+=incr;
}
// Set every LED in the array to a specified color
void fillAll(CRGB fillColor) {
for (byte i = 0; i < NUM_LEDS; i++) {
leds[i] = fillColor;
}
}
// Fade every LED in the array by a specified amount
void fadeAll(byte fadeIncr) {
for (byte i = 0; i < NUM_LEDS; i++) {
leds[i] = leds[i].fadeToBlackBy(fadeIncr);
}
}
// Shift all pixels by one, right or left (0 or 1)
void scrollArray(byte scrollDir) {
byte scrollX = 0;
for (byte x = 1; x < kMatrixWidth; x++) {
if (scrollDir == 0) {
scrollX = kMatrixWidth - x;
} else if (scrollDir == 1) {
scrollX = x - 1;
}
for (byte y = 0; y < kMatrixHeight; y++) {
leds[XY(scrollX,y)] = leds[XY(scrollX + scrollDir*2 - 1,y)];
}
}
}
// Pick a random palette from a list
void selectRandomPalette() {
switch(random8(8)) {
case 0:
currentPalette = CloudColors_p;
break;
case 1:
currentPalette = LavaColors_p;
break;
case 2:
currentPalette = OceanColors_p;
break;
case 4:
currentPalette = ForestColors_p;
break;
case 5:
currentPalette = RainbowColors_p;
break;
case 6:
currentPalette = PartyColors_p;
break;
case 7:
currentPalette = HeatColors_p;
break;
}
}
// Interrupt normal operation to indicate that auto cycle mode has changed
void confirmBlink() {
if (autoCycle) { // one blue blink, auto mode active
fillAll(CRGB::DarkBlue);
FastLED.show();
FastLED.delay(200);
fillAll(CRGB::Black);
FastLED.delay(200);
} else { // two red blinks, manual mode active
fillAll(CRGB::DarkRed);
FastLED.show();
FastLED.delay(200);
fillAll(CRGB::Black);
FastLED.delay(200);
fillAll(CRGB::DarkRed);
FastLED.show();
FastLED.delay(200);
fillAll(CRGB::Black);
FastLED.delay(200);
}
}