-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathripple.ino
60 lines (52 loc) · 1.72 KB
/
ripple.ino
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
/*
* Standby: Ripple with or without background
*/
void ripple(boolean show_background) {
const float RIPPLE_FADE_RATE = 0.80;
const uint8_t MAX_STEPS = 16;
static uint8_t rippleColor = 0;
static uint8_t rippleCenter = 0;
static int rippleStep = -1;
// -- fill background --
EVERY_N_MILLISECONDS(10) {
myhue++;
}
if (show_background) {
fill_solid(ledsLeft, N_PIXELS, CHSV(myhue, 255, 128));
} else {
fill_solid(ledsLeft, N_PIXELS, CRGB::Black);
}
EVERY_N_MILLISECONDS(50) {
// -- do ripple --
if (rippleStep == -1) {
rippleCenter = random(N_PIXELS);
rippleColor = myhue + 128;
rippleStep = 0;
}
if (rippleStep == 0) {
ledsLeft[rippleCenter] = CHSV(rippleColor, 255, 255);
rippleStep++;
} else {
if (rippleStep < MAX_STEPS) {
ledsLeft[wrap(rippleCenter + rippleStep)] = CHSV(rippleColor, 255, pow(RIPPLE_FADE_RATE, rippleStep) * 255);
ledsLeft[wrap(rippleCenter - rippleStep)] = CHSV(rippleColor, 255, pow(RIPPLE_FADE_RATE, rippleStep) * 255);
if (rippleStep > 3) {
ledsLeft[wrap(rippleCenter + rippleStep - 3)] = CHSV(rippleColor, 255, pow(RIPPLE_FADE_RATE, rippleStep - 2) * 255);
ledsLeft[wrap(rippleCenter - rippleStep + 3)] = CHSV(rippleColor, 255, pow(RIPPLE_FADE_RATE, rippleStep - 2) * 255);
}
rippleStep++;
} else {
rippleStep = -1;
}
}
}
// Copy left LED array into right LED array
copyLeftToRight();
FastLED.show();
delay(50);
}
int wrap(int rippleStep) {
if (rippleStep < 0) return N_PIXELS + rippleStep;
if (rippleStep > N_PIXELS - 1) return rippleStep - N_PIXELS;
return rippleStep;
}