-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBackground.cpp
More file actions
73 lines (55 loc) · 1.92 KB
/
Background.cpp
File metadata and controls
73 lines (55 loc) · 1.92 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
#include "Background.h"
const String Background::name[] = {"rainbow", "cycle", "off", "color", "beat"};
const String Background::prettyName[] = {"Rainbow", "Cycles hues", "Off", "Solid color", "Heartbeat"};
void Background::execute(CRGB* bgLeds) {
if(this->bgTimer == NULL)
this->bgTimer = new CEveryNMillis(1000/FRAMES_PER_SECOND);
if(this->bgTimer)
this->frame++;
if(this->millisStart == -1) {
this->millisStart = millis();
}
this->animate(bgLeds);
}
void Background::animate(CRGB* leds) {
Serial.println("Default BG animate!!!");
return;
}
void Background::fillRainbow(CRGB * pFirstLED, int numToFill, uint8_t initialhue, uint8_t deltahue, uint8_t value) {
CHSV hsv;
hsv.hue = initialhue;
hsv.val = value;
hsv.sat = 240;
for(int i = 0; i < numToFill; i++) {
pFirstLED[i] = hsv;
hsv.hue += deltahue;
}
}
void OffBackground::animate(CRGB* leds) {
fill_solid(leds, NUM_LEDS, 0x000000);
}
void ColorBackground::animate(CRGB* leds) {
fill_solid(leds, NUM_LEDS, this->color);
}
void BeatBackground::animate(CRGB* leds) {
uint8_t beat = beatsin8(this->bpm, 128, 255, this->millisStart, 64);
CRGB c(this->color);
c.nscale8(beat); // Sinusoid beat, starting at highest brightness
fill_solid(leds, NUM_LEDS, c);
}
void RainbowBackground::animate(CRGB* leds) {
// fract8 progress = this->frame % 256;
fract8 progress = beat8(this->bpm, this->millisStart);
if(reversed) {
this->fillRainbow(leds, NUM_LEDS/2, progress, 10, dim8_raw(BG_BRIGHTNESS)); // Forward
this->fillRainbow(&leds[NUM_LEDS/2], NUM_LEDS/2, progress, -10, dim8_raw(BG_BRIGHTNESS)); // Aaand back
}
else {
this->fillRainbow(leds, NUM_LEDS, progress, 10, dim8_raw(BG_BRIGHTNESS));
}
}
void CycleBackground::animate(CRGB* leds) {
// fract8 progress = this->frame % 256;
fract8 progress = beat8(this->bpm, this->millisStart);
this->fillRainbow(leds, NUM_LEDS, progress, 0, dim8_raw(BG_BRIGHTNESS));
}