104 lines
2.9 KiB
C++
104 lines
2.9 KiB
C++
/**
|
|
* Original NeoPattern code by Bill Earl
|
|
* https://learn.adafruit.com/multi-tasking-the-arduino-part-3/overview
|
|
*
|
|
* Custom modifications by 0x1d:
|
|
* - default OnComplete callback that sets pattern to reverse
|
|
* - separate animation update from timer; Update now updates directly, UpdateScheduled uses timer
|
|
*/
|
|
#ifndef __NeoPattern_INCLUDED__
|
|
#define __NeoPattern_INCLUDED__
|
|
|
|
#include <Adafruit_NeoPixel.h>
|
|
|
|
using namespace std;
|
|
|
|
// Pattern types supported:
|
|
enum pattern
|
|
{
|
|
NONE = 0,
|
|
RAINBOW_CYCLE = 1,
|
|
THEATER_CHASE = 2,
|
|
COLOR_WIPE = 3,
|
|
SCANNER = 4,
|
|
FADE = 5,
|
|
FIRE = 6
|
|
};
|
|
|
|
// Pattern directions supported:
|
|
enum direction
|
|
{
|
|
FORWARD,
|
|
REVERSE
|
|
};
|
|
|
|
// NeoPattern Class - derived from the Adafruit_NeoPixel class
|
|
class NeoPattern : public Adafruit_NeoPixel
|
|
{
|
|
public:
|
|
// Member Variables:
|
|
pattern ActivePattern = RAINBOW_CYCLE; // which pattern is running
|
|
direction Direction = FORWARD; // direction to run the pattern
|
|
|
|
unsigned long Interval = 150; // milliseconds between updates
|
|
unsigned long lastUpdate = 0; // last update of position
|
|
|
|
uint32_t Color1 = 0;
|
|
uint32_t Color2 = 0; // What colors are in use
|
|
uint16_t TotalSteps = 32; // total number of steps in the pattern
|
|
uint16_t Index; // current step within the pattern
|
|
uint16_t completed = 0;
|
|
|
|
// Callback on completion of pattern
|
|
void (*OnComplete)(int);
|
|
|
|
// Constructor - calls base-class constructor to initialize strip
|
|
NeoPattern(uint16_t pixels, uint8_t pin, uint8_t type, void (*callback)(int));
|
|
NeoPattern(uint16_t pixels, uint8_t pin, uint8_t type);
|
|
~NeoPattern();
|
|
|
|
// Stream handling functions removed
|
|
|
|
// Pattern completion
|
|
void onCompleteDefault(int pixels);
|
|
|
|
// Pattern control
|
|
void Increment();
|
|
void Reverse();
|
|
|
|
// Rainbow Cycle
|
|
void RainbowCycle(uint8_t interval, direction dir = FORWARD);
|
|
void RainbowCycleUpdate();
|
|
|
|
// Theater Chase
|
|
void TheaterChase(uint32_t color1, uint32_t color2, uint16_t interval, direction dir = FORWARD);
|
|
void TheaterChaseUpdate();
|
|
|
|
// Color Wipe
|
|
void ColorWipe(uint32_t color, uint8_t interval, direction dir = FORWARD);
|
|
void ColorWipeUpdate();
|
|
|
|
// Scanner
|
|
void Scanner(uint32_t color1, uint8_t interval);
|
|
void ScannerUpdate();
|
|
|
|
// Fade
|
|
void Fade(uint32_t color1, uint32_t color2, uint16_t steps, uint8_t interval, direction dir = FORWARD);
|
|
void FadeUpdate();
|
|
|
|
// Fire effect
|
|
void Fire(int Cooling, int Sparking);
|
|
void setPixelHeatColor(int Pixel, uint8_t temperature);
|
|
void setPixel(int Pixel, uint8_t red, uint8_t green, uint8_t blue);
|
|
void showStrip();
|
|
|
|
// Utility methods
|
|
uint32_t DimColor(uint32_t color);
|
|
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(uint8_t WheelPos);
|
|
};
|
|
|
|
#endif |