-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCandyCane.h
69 lines (64 loc) · 2.27 KB
/
CandyCane.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
//
// pattern with alternating color stripes either falling or going in a circle
//
class CandyCane: public PatternBase {
const int cane_size = 10;
const float cane_reduce = 0.5;
int cane_offset=0;
long next_cane_fade=0;
int cane_increment = 10;
bool done_cane_fade = false;
bool doCircle = false;
CRGB top_color;
CRGB bottom_color;
public:
CandyCane(ShapedLED* shape, ColorPalette* default_palette): PatternBase(shape, default_palette) {
pattern_run_delay = 5;
}
void setDoCircle(bool doCircle) {
this->doCircle = doCircle;
}
void run() {
// if it is time to animate the candy cane
if (timeToRun()) {
if (doCircle) {
top_color = CRGB(0, 0, default_palette->getIntensity() * cane_reduce);
bottom_color = CRGB(default_palette->getIntensity() * cane_reduce, default_palette->getIntensity() * cane_reduce, default_palette->getIntensity() * cane_reduce);
} else {
top_color = CRGB(default_palette->getIntensity() * cane_reduce, 0, 0);
bottom_color = CRGB(default_palette->getIntensity() * cane_reduce, default_palette->getIntensity() * cane_reduce, default_palette->getIntensity() * cane_reduce);
}
if (!done_cane_fade) {
done_cane_fade = true;
for(int right_idx=shape->bottom_right; right_idx < shape->top_right; right_idx++) {
int left_idx;
if (doCircle)
left_idx = shape->top_left + right_idx;
else
left_idx = shape->bottom_left - right_idx;
int colorIndex = (right_idx + cane_offset) % cane_size;
CRGB newColor;
if (colorIndex < cane_size / 2)
newColor = top_color;
else
newColor = bottom_color;
//if any color is not done fading, keep fading
if (!FadeUtils::fadeTo(shape->leds, right_idx, newColor, cane_increment)) {
done_cane_fade = false;
}
FadeUtils::fadeTo(shape->leds, left_idx, newColor, cane_increment);
}
FastLED.show();
} else {
// move cane down or reset to top
if (cane_offset < cane_size) {
cane_offset++;
} else {
cane_offset = 0;
}
done_cane_fade = false;
} // done fading
setNextRun();
} // time to fade
}
};