-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPatternRunner.h
194 lines (174 loc) · 4.63 KB
/
PatternRunner.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
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
#include <FastLED.h>
#include "FadeUtils.h"
#include "ShapedLED.h"
#include "PatternBase.h"
#include "Twinkler.h"
#include "TwinklerGroup.h"
#include "Sparkler.h"
#include "ColorPulseWipe.h"
#include "Icicle.h"
#include "CandyCane.h"
#include "StrangerLights.h"
#define MODE_OFF 0
#define MODE_SOLID 1
#define MODE_ROLLING 2
#define SPARKLE_PATTERN 0
#define ICICLE_PATTERN 1
#define CANDY_CANE_PATTERN 2
#define CIRCLE_CANE_PATTERN 3
#define UPDOWN_WIPE_PATTERN 4
#define PULSE_PATTERN 5
#define RETRO_TWINKLE_PATTERN 6
#define RAINBOW_TWINKLE_PATTERN 7
#define WHITE_TWINKLE_PATTERN 8
#define STRANGE_PATTERN 9
#define MAX_PATTERN_IDX 9
//
// controller to work with a variety of patterns and run/adjust them
//
class PatternRunner {
const int pattern_display_time = 6000;
long pattern_end_time = 0;
int current_pattern_mode = MODE_OFF;
int current_pattern_idx = SPARKLE_PATTERN;
PatternBase* cur_pattern = NULL;
ColorPalette default_palette;
ColorPalette retro;
ColorPalette classic;
ColorPalette white;
Sparkler sparkle;
Icicle icicle;
CandyCane cane;
ColorWipe wiper;
ColorPulser pulser;
TwinklerGroup twinkler_group;
StrangerLights strange;
ShapedLED* shape;
void turnOff() {
for (int i=0; i < shape->num_leds; i++) {
shape->leds[i].r = 0;
shape->leds[i].g = 0;
shape->leds[i].b = 0;
}
FastLED.show();
}
void runCurrentPattern() {
if (cur_pattern != NULL)
cur_pattern->run();
}
public:
PatternRunner(ShapedLED* shape):
shape(shape),
sparkle(shape, &default_palette),
pulser(shape, &default_palette),
icicle(shape, &default_palette),
cane(shape, &default_palette),
wiper(shape, &default_palette),
twinkler_group(shape, &default_palette),
strange(shape, &default_palette) {
initPattern();
}
void initPalettes() {
retro.clearPalette();
retro.addColor(CRGB::HotPink);
retro.addColor(CRGB::Turquoise);
retro.addColor(CRGB::DeepPink);
retro.addColor(CRGB::Turquoise);
classic.clearPalette();
classic.addColor(CRGB::Green);
classic.addColor(CRGB::Blue);
classic.addColor(CRGB::Red);
classic.addColor(CRGB::Gold);
white.clearPalette();
white.addColor(CRGB::AntiqueWhite);
}
void runLoop() {
switch (current_pattern_mode) {
case MODE_OFF:
turnOff();
break;
case MODE_ROLLING:
if (millis() > pattern_end_time) {
nextPattern();
pattern_end_time = millis() + pattern_display_time;
}
runCurrentPattern();
break;
case MODE_SOLID:
runCurrentPattern();
break;
}
}
void setMode(int new_mode) {
current_pattern_mode = new_mode;
if (current_pattern_mode == MODE_OFF)
turnOff();
}
void initPattern() {
switch(current_pattern_idx) {
case SPARKLE_PATTERN:
cur_pattern = &sparkle;
break;
case ICICLE_PATTERN:
cur_pattern = &icicle;
break;
case CIRCLE_CANE_PATTERN:
cane.setDoCircle(true);
cur_pattern = &cane;
break;
case CANDY_CANE_PATTERN:
cane.setDoCircle(false);
cur_pattern = &cane;
break;
case RETRO_TWINKLE_PATTERN:
twinkler_group.setup(TwinklerGroup::MAX_TWINKLERS, 0.0, 1.0, 0.03, 50, &retro);
cur_pattern = &twinkler_group;
break;
case RAINBOW_TWINKLE_PATTERN:
twinkler_group.setup(TwinklerGroup::MAX_TWINKLERS, 0.0, 1.0, 0.03, 50, &classic);
cur_pattern = &twinkler_group;
break;
case WHITE_TWINKLE_PATTERN:
twinkler_group.setup(TwinklerGroup::MAX_TWINKLERS, 0.0, 1.0, 0.03, 50, &white);
cur_pattern = &twinkler_group;
break;
case UPDOWN_WIPE_PATTERN:
cur_pattern = &wiper;
break;
case PULSE_PATTERN:
cur_pattern = &pulser;
break;
case STRANGE_PATTERN:
cur_pattern = &strange;
break;
}
}
void nextPattern() {
turnOff();
current_pattern_idx++;
if (current_pattern_idx > MAX_PATTERN_IDX)
current_pattern_idx = 0;
initPattern();
}
void prevPattern() {
turnOff();
current_pattern_idx--;
if (current_pattern_idx < 0)
current_pattern_idx = MAX_PATTERN_IDX;
initPattern();
}
void increaseBrightness() {
default_palette.increaseBrightness();
retro.increaseBrightness();
classic.increaseBrightness();
white.increaseBrightness();
initPalettes();
}
void decreaseBrightness() {
default_palette.decreaseBrightness();
retro.decreaseBrightness();
classic.decreaseBrightness();
white.decreaseBrightness();
initPalettes();
}
};