| Line | |
|---|
| 1 | #ifndef RAINBOWCYCLEDEMO_H |
|---|
| 2 | #define RAINBOWCYCLEDEMO_H |
|---|
| 3 | |
|---|
| 4 | #include "Demo.h" |
|---|
| 5 | |
|---|
| 6 | // Animation speeds to loop through with mode presses. The current milliseconds |
|---|
| 7 | // are divided by this value so the smaller the value the faster the animation. |
|---|
| 8 | static int speeds[] = { 5, 10, 50, 100 }; |
|---|
| 9 | |
|---|
| 10 | class RainbowCycleDemo: public Demo { |
|---|
| 11 | public: |
|---|
| 12 | RainbowCycleDemo() { currentSpeed = 0; } |
|---|
| 13 | ~RainbowCycleDemo() {} |
|---|
| 14 | |
|---|
| 15 | virtual void loop() { |
|---|
| 16 | // Make an offset based on the current millisecond count scaled by the current speed. |
|---|
| 17 | uint32_t offset = millis() / speeds[currentSpeed]; |
|---|
| 18 | // Loop through each pixel and set it to an incremental color wheel value. |
|---|
| 19 | for(int i=0; i<10; ++i) { |
|---|
| 20 | CircuitPlayground.strip.setPixelColor(i, CircuitPlayground.colorWheel(((i * 256 / 10) + offset) & 255)); |
|---|
| 21 | } |
|---|
| 22 | // Show all the pixels. |
|---|
| 23 | CircuitPlayground.strip.show(); |
|---|
| 24 | } |
|---|
| 25 | |
|---|
| 26 | virtual void modePress() { |
|---|
| 27 | // Increment through the available speeds. |
|---|
| 28 | currentSpeed += 1; |
|---|
| 29 | if (currentSpeed >= sizeof(speeds)/sizeof(int)) { |
|---|
| 30 | currentSpeed = 0; |
|---|
| 31 | } |
|---|
| 32 | } |
|---|
| 33 | |
|---|
| 34 | private: |
|---|
| 35 | int currentSpeed; |
|---|
| 36 | |
|---|
| 37 | }; |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | #endif |
|---|
Note: See
TracBrowser
for help on using the repository browser.