-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRainbow.h
40 lines (35 loc) · 1.12 KB
/
Rainbow.h
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
#include <FastLED.h>
#include <Animations.h>
class Rainbow : public Animation
{
private:
static const int palletSize = 7;
const CRGB rainbows[palletSize] = {
CRGB::Red,
CRGB::Orange,
CRGB::Yellow,
CRGB::Green,
CRGB::Blue,
CRGB::Indigo,
CRGB::Violet
};
int frameIndex = 0;
const CRGB* getBackgroundColor(int frame, int strip, int led)
{
int colorIndex = (led + frame + strip) % palletSize;
return &rainbows[colorIndex];
}
public:
void draw(CRGB (*canvas)[NUM_STRIPS][NUM_LEDS])
{
for (int ledIndex = 0; ledIndex < NUM_LEDS; ledIndex++)
{
for (int stripIndex = 0; stripIndex < NUM_STRIPS; stripIndex++)
{
(*canvas)[stripIndex][ledIndex] = *getBackgroundColor(frameIndex, stripIndex, ledIndex);
}
}
// Increment frame to next index
frameIndex = (frameIndex + 1) % palletSize;
}
};