source: trunk/Arduino/libraries/Adafruit_Circuit_Playground/examples/mega_demo/RainbowCycleDemo.h

Last change on this file was 3, checked in by markus, 7 years ago

Setup project structure

File size: 1.1 KB
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.
8static int speeds[] = { 5, 10, 50, 100 };
9
10class RainbowCycleDemo: public Demo {
11public:
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
34private:
35  int currentSpeed;
36 
37};
38
39
40#endif
Note: See TracBrowser for help on using the repository browser.