-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathripple.h
More file actions
51 lines (34 loc) · 2.36 KB
/
ripple.h
File metadata and controls
51 lines (34 loc) · 2.36 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
#ifndef RIPPLE_H
#define RIPPLE_H
void ripple() { // Display ripples triggered by peaks.
// Local definitions
#define maxsteps 16 // Maximum number of steps.
// Persistent local variables.
static uint8_t colour; // Ripple colour is based on samples.
static uint16_t center = 0; // Center of current ripple.
static int8_t step = -1; // Phase of the ripple as it spreads out.
timeval = 20; // Our EVERY_N_MILLIS_I timer value.
if (samplepeak == 1) {step = -1;} // Trigger a new ripple if we have a peak.
fadeToBlackBy(leds, NUM_LEDS, 64); // Fade the strand, where 1 = slow, 255 = fast
switch (step) {
case -1: // Initialize ripple variables. By Andrew Tuline.
center = random(NUM_LEDS);
colour = (oldsample) % 255; // More peaks/s = higher the hue colour.
step = 0;
break;
case 0:
leds[center] += ColorFromPalette(currentPalette, colour, 255, currentBlending); // Display the first pixel of the ripple.
step ++;
break;
case maxsteps: // At the end of the ripples.
// step = -1;
break;
default: // Middle of the ripples.
leds[(center + step + NUM_LEDS) % NUM_LEDS] += ColorFromPalette(currentPalette, colour, 255/step*2, currentBlending); // A spreading and fading pattern up the strand.
leds[(center - step + NUM_LEDS) % NUM_LEDS] += ColorFromPalette(currentPalette, colour, 255/step*2, currentBlending); // A spreading and fading pattern down the strand.
step ++; // Next step.
break;
} // switch step
addGlitter(sampleavg); // Add glitter baesd on sampleavg.
} // ripple()
#endif