/
RainbowCycle.h
39 lines (32 loc) · 1.08 KB
/
RainbowCycle.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
#ifndef RAINBOWCYCLE_H
#define RAINBOWCYCLE_H
#include "Demo.h"
// Animation speeds to loop through with mode presses. The current milliseconds
// are divided by this value so the smaller the value the faster the animation.
static int speeds[] = { 5, 10, 50, 100 };
class RainbowCycle: public Demo {
public:
RainbowCycle() { currentSpeed = 0; }
~RainbowCycle() {}
virtual void loop() {
Serial.println("Rainbow Cycle Demo:");
// Make an offset based on the current millisecond count scaled by the current speed.
uint32_t offset = millis() / speeds[currentSpeed];
// Loop through each pixel and set it to an incremental color wheel value.
for(int i=0; i<10; ++i) {
CircuitPlayground.strip.setPixelColor(i, CircuitPlayground.colorWheel(((i * 256 / 10) + offset) & 255));
}
// Show all the pixels.
CircuitPlayground.strip.show();
}
virtual void modePress() {
// Increment through the available speeds.
currentSpeed += 1;
if (currentSpeed >= sizeof(speeds)/sizeof(int)) {
currentSpeed = 0;
}
}
private:
int currentSpeed;
};
#endif