-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnimations.h
More file actions
110 lines (83 loc) · 2.59 KB
/
Animations.h
File metadata and controls
110 lines (83 loc) · 2.59 KB
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
uint8_t sinelon(uint8_t bpmSpeed, uint8_t fadeAmount)
{
fadeToBlackBy(leds, NUM_LEDS, fadeAmount);
int pos = scale16(beat16(12), NUM_LEDS);
leds[pos] += CHSV(gHue, 255, 192);
return 0;
}
static uint8_t dropStripIndex = 0;
static uint8_t dropPos = 0;
static uint8_t dropHue = 0;
uint8_t drops(uint8_t colorful, uint8_t fadeAmount)
{
fadeToBlackBy(leds, NUM_LEDS, fadeAmount);
EVERY_N_MILLIS(100) {
dropPos++;
if (dropPos >= strips[dropStripIndex].mLength) {
dropPos = 0;
dropStripIndex = (dropStripIndex + 1 + random8(numberOfStrips-1)) % numberOfStrips;
dropHue = random8();
}
}
uint8_t saturation = colorful ? 255 : 0;
leds[ledPosDown(dropStripIndex, dropPos)] += CHSV(dropHue, saturation, 192);
return 0;
}
static uint8_t spiralStripIndex = 0;
static uint8_t spiralPos = 0;
uint8_t spiral(uint8_t arg0, uint8_t fadeAmount)
{
fadeToBlackBy(leds, NUM_LEDS, fadeAmount);
EVERY_N_MILLIS(100) {
spiralStripIndex++;
if (spiralStripIndex >= numberOfStrips) {
spiralStripIndex = 0;
}
}
EVERY_N_MILLIS(1000) {
spiralPos++;
if (spiralPos >= strips[spiralStripIndex].mLength) {
spiralPos = 0;
}
}
uint8_t x = ledPosUp(spiralStripIndex, spiralPos);
leds[x] += CHSV(gHue, 255, 192);
return 0;
}
static uint8_t circleStripIndex = 0;
static uint8_t circleStripIndex2 = 0;
uint8_t movingCircle(uint8_t arg0, uint8_t arg1)
{
fadeToBlackBy(leds, NUM_LEDS, 8);
EVERY_N_MILLIS(100) {
circleStripIndex = (circleStripIndex + 1) % numberOfStrips;
circleStripIndex2 = (circleStripIndex2 + (numberOfStrips-1)) % numberOfStrips;
}
Strip strip = strips[circleStripIndex];
for (int i = strip.mStart; i < strip.mStart + strip.mLength; i++) {
leds[i] += CHSV(gHue, 255, 192);
}
strip = strips[circleStripIndex2];
for (int i = strip.mStart; i < strip.mStart + strip.mLength; i++) {
leds[i] += CHSV(gHue, 255, 192);
}
return 0;
}
AnimationPattern switcherAnimations[] = {
{drops, 1, 4},
{spiral, 0, 1},
{drops, 0, 4},
{sinelon, 5, 4},
};
static const int numberOfSwitcherAnimations = sizeof(switcherAnimations) / sizeof(switcherAnimations[0]);
static uint8_t switcherCurrentAnimation = 0;
uint8_t animationSwitcher(uint8_t arg0, uint8_t arg1)
{
uint8_t x = switcherAnimations[switcherCurrentAnimation].mArg1;
uint8_t y= switcherAnimations[switcherCurrentAnimation].mArg2;
Animation animate = switcherAnimations[switcherCurrentAnimation].mPattern;
animate(x, y);
EVERY_N_MILLIS(30000) {
switcherCurrentAnimation = (switcherCurrentAnimation + 1) % numberOfSwitcherAnimations;
}
}