-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanimations.ino
More file actions
136 lines (117 loc) · 2.69 KB
/
animations.ino
File metadata and controls
136 lines (117 loc) · 2.69 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
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
// halfwidth must be an odd number
void anim_wave(int halfwidth, int steps, int stepdelay) {
int current = halfwidth;
uint8_t hue = 200;
uint8_t saturation = 255;
uint8_t values[NUM_LEDS];
uint32_t currentvalue = 0, tmpvalue = 0;
for(int i = 0; i < NUM_LEDS; i++)
values[i] = 1;
// set up initial layout
FastLED.clear();
for(int i = 1; i <= halfwidth; i++)
{
values[current+i] = 255*(halfwidth-i)/halfwidth;
values[current-i] = 255*(halfwidth-i)/halfwidth;
}
values[current] = 255;
// show our initial set up
for(int i = 0; i < NUM_LEDS; i++)
leds[i] = CHSV(hue, saturation, values[i]);
FastLED.show();
// go to next led and start the loop
current++;
while(current < steps)
{
//Serial.print("Current: ");
//Serial.println(current);
while(values[current%NUM_LEDS] < 255) // wait till current value is at 255
{
// make previous halfwidth darker
for(int i = halfwidth; i >= 1; i--)
{
values[(current-i)%NUM_LEDS]--;
}
// make current and next halfwidth brighter
for(int i = 0; i <= halfwidth-1; i++)
{
values[(current+i)%NUM_LEDS]++;
}
// Apply colors and show
for(int i = 0; i < NUM_LEDS; i++)
leds[i] = CHSV(hue, saturation, values[i]);
FastLED.show();
//Serial.println();
delay(stepdelay);
}
current++;
}
}
void anim_fade_blink(CHSV color, int stepdelay)
{
for(int b = 1; b < 255; b++)
{
color.v = b;
for(int i = 0; i < NUM_LEDS; i++)
{
leds[i] = color;
}
FastLED.show();
delay(stepdelay);
}
boolean done = false;
while(!done)
{
done = true; // set to true and see if we're done below
for(int i = 0; i < NUM_LEDS; i++)
{
leds[i].fadeToBlackBy(1);
if(leds[i])
done = false;
}
FastLED.show();
delay(stepdelay);
}
}
void cmd_anim_fade_blink()
{
char *h = SCmd.next();
char *s = SCmd.next();
char *stepdelay = SCmd.next();
if(h != NULL && s != NULL && stepdelay != NULL)
{
anim_fade_blink(CHSV(atoi(h), atoi(s), 1), atoi(stepdelay));
Serial.println("200 Fade Blink.");
}
else
{
Serial.println("400 Bad Request");
}
}
void anim_all_rainbow(int steps, int stepdelay)
{
CHSV start (0, 255, 255);
while(steps-- > 0)
{
start.hue += 1;
fill_solid(&leds[0], 16, start);
FastLED.show();
delay(stepdelay);
}
}
void fade_all_to_black(int stepdelay)
{
boolean done = false;
while(!done)
{
done = true; // set to true and see if we're done below
for(int i = 0; i < NUM_LEDS; i++)
{
leds[i].fadeToBlackBy(1);
if(leds[i])
done = false;
}
FastLED.show();
delay(stepdelay);
}
}