60 lines
1.8 KiB
C++
60 lines
1.8 KiB
C++
#include <Adafruit_NeoPixel.h>
|
|
|
|
// Pattern types supported:
|
|
enum pattern { NONE, RAINBOW_CYCLE, THEATER_CHASE, COLOR_WIPE, SCANNER, FADE, RANDOM_FADE };
|
|
// Patern directions supported:
|
|
enum direction { FORWARD, REVERSE };
|
|
|
|
class NeoPatterns : public Adafruit_NeoPixel
|
|
{
|
|
public:
|
|
NeoPatterns(uint16_t pixels, uint8_t pin, uint8_t type, void (*callback)());
|
|
|
|
void Update();
|
|
|
|
void Reverse();
|
|
void None();
|
|
void RainbowCycle(uint8_t interval, direction dir = FORWARD);
|
|
void RainbowCycleUpdate();
|
|
void TheaterChase(uint32_t color1, uint32_t color2, uint8_t interval, direction dir = FORWARD);
|
|
void TheaterChaseUpdate();
|
|
void ColorWipe(uint32_t color, uint8_t interval, direction dir = FORWARD);
|
|
void ColorWipeUpdate();
|
|
void Scanner(uint32_t color1, uint8_t interval = 40,bool colorful = false);
|
|
void ScannerUpdate();
|
|
void Fade(uint32_t color1, uint32_t color2, uint16_t steps, uint8_t interval, direction dir = FORWARD);
|
|
void FadeUpdate();
|
|
void RandomFade(uint8_t interval = 100);
|
|
void RandomFadeUpdate();
|
|
|
|
void SetColor1(uint32_t color);
|
|
void SetColor2(uint32_t color);
|
|
//Utilities
|
|
void ColorSet(uint32_t color);
|
|
uint8_t Red(uint32_t color);
|
|
uint8_t Green(uint32_t color);
|
|
uint8_t Blue(uint32_t color);
|
|
uint32_t Wheel(byte WheelPos);
|
|
|
|
private:
|
|
|
|
// Member Variables:
|
|
pattern ActivePattern; // which pattern is running
|
|
direction Direction; // direction to run the pattern
|
|
|
|
unsigned long Interval; // milliseconds between updates
|
|
unsigned long lastUpdate; // last update of position
|
|
|
|
uint32_t Color1, Color2; // What colors are in use
|
|
uint16_t TotalSteps; // total number of steps in the pattern
|
|
uint16_t Index; // current step within the pattern
|
|
|
|
byte wPos;
|
|
bool colorful;
|
|
|
|
uint32_t DimColor(uint32_t color);
|
|
void Increment();
|
|
void (*OnComplete)(); // Callback on completion of pattern
|
|
|
|
};
|