2017-02-28 21:56:04 +00:00
|
|
|
#include <Adafruit_NeoPixel.h>
|
2017-03-01 20:41:27 +00:00
|
|
|
#include "font.h"
|
2017-02-28 21:56:04 +00:00
|
|
|
|
|
|
|
// Pattern types supported:
|
2017-03-03 17:27:51 +00:00
|
|
|
enum pattern { NONE, RAINBOW_CYCLE, THEATER_CHASE, COLOR_WIPE, SCANNER, FADE, RANDOM_FADE, SMOOTH, ICON, RANDOM_FADE_SINGLE, PLASMA, FILL, RANDOM };
|
2017-02-28 21:56:04 +00:00
|
|
|
// Patern directions supported:
|
|
|
|
enum direction { FORWARD, REVERSE };
|
|
|
|
|
|
|
|
class NeoPatterns : public Adafruit_NeoPixel
|
|
|
|
{
|
2017-02-28 23:02:17 +00:00
|
|
|
public:
|
|
|
|
NeoPatterns(uint16_t pixels, uint8_t pin, uint8_t type, void (*callback)());
|
|
|
|
|
|
|
|
void Update();
|
|
|
|
void Reverse();
|
2017-03-03 17:27:51 +00:00
|
|
|
void None(uint8_t interval = 40);
|
2017-07-04 23:01:41 +00:00
|
|
|
void Stop(uint8_t interval = 40);
|
2017-02-28 23:02:17 +00:00
|
|
|
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();
|
2017-03-01 20:41:27 +00:00
|
|
|
void Scanner(uint32_t color1 = 16711680, uint8_t interval = 40, bool colorful = false, bool spiral = false);
|
2017-02-28 23:02:17 +00:00
|
|
|
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();
|
2017-03-01 20:41:27 +00:00
|
|
|
void RandomFadeSingle(uint8_t interval = 100, uint8_t speed = 5);
|
|
|
|
void RandomFadeSingleUpdate();
|
|
|
|
void RandomBuffer();
|
|
|
|
void Random();
|
2017-03-01 16:37:20 +00:00
|
|
|
void Smooth(uint8_t wheelSpeed = 16, uint8_t smoothing = 80, uint8_t strength = 50, uint8_t interval = 40);
|
2017-03-01 15:21:34 +00:00
|
|
|
void SmoothUpdate();
|
2017-03-01 20:41:27 +00:00
|
|
|
void Icon(uint8_t fontchar, String iconcolor = "#FFFFFF", uint8_t interval = 30);
|
|
|
|
void IconUpdate();
|
|
|
|
void IconComplete();
|
2017-03-07 22:26:02 +00:00
|
|
|
void Plasma(float phase = 0, float phaseIncrement = 0.08, float colorStretch = 0.11, uint8_t interval = 60); // 0.08 and 0.11 // 0.03 und 0.3
|
2017-03-02 10:06:29 +00:00
|
|
|
void PlasmaUpdate();
|
2017-02-28 23:02:17 +00:00
|
|
|
|
|
|
|
void SetColor1(uint32_t color);
|
|
|
|
void SetColor2(uint32_t color);
|
|
|
|
//Utilities
|
|
|
|
void ColorSet(uint32_t color);
|
2017-03-01 16:37:20 +00:00
|
|
|
void ColorSetParameters(String parameters);
|
2017-02-28 23:02:17 +00:00
|
|
|
uint8_t Red(uint32_t color);
|
|
|
|
uint8_t Green(uint32_t color);
|
|
|
|
uint8_t Blue(uint32_t color);
|
|
|
|
uint32_t Wheel(byte WheelPos);
|
|
|
|
uint8_t numToSpiralPos(int num);
|
|
|
|
uint8_t xyToPos(int x, int y);
|
2017-03-01 16:37:20 +00:00
|
|
|
uint8_t numToPos(int num);
|
2017-03-01 15:21:34 +00:00
|
|
|
uint8_t getAverage(uint8_t array[], uint8_t i, int x, int y);
|
2017-03-01 16:37:20 +00:00
|
|
|
uint32_t parseColor(String value);
|
2017-03-01 20:41:27 +00:00
|
|
|
private:
|
2017-02-28 23:02:17 +00:00
|
|
|
|
|
|
|
// Member Variables:
|
|
|
|
pattern ActivePattern; // which pattern is running
|
2017-03-01 20:41:27 +00:00
|
|
|
pattern SavedPattern;
|
2017-02-28 23:02:17 +00:00
|
|
|
direction Direction; // direction to run the pattern
|
2017-03-01 20:41:27 +00:00
|
|
|
direction SavedDirection;
|
2017-02-28 23:02:17 +00:00
|
|
|
|
|
|
|
unsigned long Interval; // milliseconds between updates
|
2017-03-01 20:41:27 +00:00
|
|
|
unsigned long SavedInterval;
|
2017-02-28 23:02:17 +00:00
|
|
|
unsigned long lastUpdate; // last update of position
|
|
|
|
|
|
|
|
uint32_t Color1, Color2; // What colors are in use
|
2017-03-01 20:41:27 +00:00
|
|
|
uint32_t SavedColor1;
|
2017-02-28 23:02:17 +00:00
|
|
|
uint16_t TotalSteps; // total number of steps in the pattern
|
2017-03-01 20:41:27 +00:00
|
|
|
uint16_t SavedTotalSteps;
|
2017-02-28 23:02:17 +00:00
|
|
|
uint16_t Index; // current step within the pattern
|
2017-03-01 20:41:27 +00:00
|
|
|
uint16_t SavedIndex;
|
2017-03-01 16:37:20 +00:00
|
|
|
uint8_t Every; // Turn every "Every" pixel in Color1/Color2
|
2017-02-28 23:02:17 +00:00
|
|
|
|
|
|
|
byte wPos;
|
|
|
|
bool colorful;
|
|
|
|
bool spiral;
|
2017-03-01 15:21:34 +00:00
|
|
|
uint8_t wPosSlow;
|
|
|
|
uint8_t WheelSpeed;
|
|
|
|
uint8_t Smoothing;
|
|
|
|
uint8_t Strength;
|
|
|
|
uint8_t movingPoint_x;
|
|
|
|
uint8_t movingPoint_y;
|
|
|
|
uint8_t *pixelR;
|
|
|
|
uint8_t *pixelG;
|
|
|
|
uint8_t *pixelB;
|
|
|
|
uint8_t *pixelR_buffer;
|
|
|
|
uint8_t *pixelG_buffer;
|
2017-03-01 20:41:27 +00:00
|
|
|
uint8_t *pixelB_buffer;
|
|
|
|
|
|
|
|
uint8_t FontChar;
|
2017-02-28 23:02:17 +00:00
|
|
|
|
2017-03-02 10:06:29 +00:00
|
|
|
float PlasmaPhase;
|
2017-03-03 17:27:51 +00:00
|
|
|
float SavedPlasmaPhase;
|
2017-03-02 10:06:29 +00:00
|
|
|
float PlasmaPhaseIncrement;
|
2017-03-03 17:27:51 +00:00
|
|
|
float SavedPlasmaPhaseIncrement;
|
2017-03-02 10:06:29 +00:00
|
|
|
float PlasmaColorStretch;
|
2017-03-03 17:27:51 +00:00
|
|
|
float SavedPlasmaColorStretch;
|
|
|
|
|
2017-03-02 10:06:29 +00:00
|
|
|
|
2017-02-28 23:02:17 +00:00
|
|
|
uint32_t DimColor(uint32_t color);
|
|
|
|
void Increment();
|
|
|
|
void (*OnComplete)(); // Callback on completion of pattern
|
2017-02-28 21:56:04 +00:00
|
|
|
|
2017-03-02 10:06:29 +00:00
|
|
|
// Convenient 2D point structure
|
|
|
|
struct Point {
|
|
|
|
float x;
|
|
|
|
float y;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-02-28 21:56:04 +00:00
|
|
|
};
|