forked from macetech/RGBShades
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.h
144 lines (119 loc) · 3.7 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
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
// Assorted useful functions and variables
// Global 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 = false; // flag for automatic effect changes
byte currentBrightness = STARTBRIGHTNESS; // 0-255 will be scaled to 0-MAXBRIGHTNESS
CRGBPalette16 currentPalette(RainbowColors_p); // global palette storage
// Global variables for text
#define TXT_NORMAL 0
#define TXT_RAINBOW 1
#define TXT_CHARSPACING 2
String displayString = "HELLO! ";
String displayPlaceholder = displayString;
boolean okayToSwitch = 0;
byte textStyle = TXT_RAINBOW;
CRGB textFgColor;
CRGB textBgColor;
typedef void (*functionList)(); // definition for list of effect function pointers
extern const byte numEffects;
// 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);
}
}
// Fetch font character bitmap from flash
byte charBuffer[5] = {0};
void loadCharBuffer(byte character) {
byte mappedCharacter = character;
if (mappedCharacter >= 32 && mappedCharacter <= 95) {
mappedCharacter -= 32; // subtract font array offset
} else if (mappedCharacter >= 97 && mappedCharacter <= 122) {
mappedCharacter -= 64; // subtract font array offset and convert lowercase to uppercase
} else {
mappedCharacter = 96; // unknown character block
}
for (byte i = 0; i < 5; i++) {
charBuffer[i] = (byte) Font[mappedCharacter][i];
}
}