New randomscanner and randomfade effect
This commit is contained in:
parent
0a4eda713d
commit
7673b4e19c
|
@ -27,6 +27,9 @@ void NeoPatterns::Update(){
|
|||
case FADE:
|
||||
FadeUpdate();
|
||||
break;
|
||||
case RANDOM_FADE:
|
||||
RandomFadeUpdate();
|
||||
break;
|
||||
case NONE:
|
||||
break;
|
||||
default:
|
||||
|
@ -146,18 +149,29 @@ void NeoPatterns::ColorWipeUpdate()
|
|||
}
|
||||
|
||||
// Initialize for a SCANNNER
|
||||
void NeoPatterns::Scanner(uint32_t color1, uint8_t interval)
|
||||
void NeoPatterns::Scanner(uint32_t color1, uint8_t interval, bool colorful)
|
||||
{
|
||||
ActivePattern = SCANNER;
|
||||
Interval = interval;
|
||||
TotalSteps = (numPixels() - 1) * 2;
|
||||
Color1 = color1;
|
||||
Index = 0;
|
||||
wPos = 0;
|
||||
this->colorful = colorful;
|
||||
}
|
||||
|
||||
// Update the Scanner Pattern
|
||||
void NeoPatterns::ScannerUpdate()
|
||||
{
|
||||
if(colorful) {
|
||||
Color1 = Wheel(wPos);
|
||||
if(wPos >= 255) {
|
||||
wPos =0;
|
||||
}
|
||||
else {
|
||||
wPos++;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < numPixels(); i++)
|
||||
{
|
||||
if (i == Index) // Scan Pixel to the right
|
||||
|
@ -175,6 +189,7 @@ void NeoPatterns::ScannerUpdate()
|
|||
}
|
||||
show();
|
||||
Increment();
|
||||
|
||||
}
|
||||
|
||||
void NeoPatterns::Fade(uint32_t color1, uint32_t color2, uint16_t steps, uint8_t interval, direction dir)
|
||||
|
@ -202,6 +217,17 @@ void NeoPatterns::FadeUpdate()
|
|||
Increment();
|
||||
}
|
||||
|
||||
void NeoPatterns::RandomFade(uint8_t interval ){
|
||||
ActivePattern = RANDOM_FADE;
|
||||
Interval = interval;
|
||||
TotalSteps = 255;
|
||||
Index = 0;
|
||||
}
|
||||
void NeoPatterns::RandomFadeUpdate(){
|
||||
ColorSet(Wheel(Index));
|
||||
Increment();
|
||||
}
|
||||
|
||||
// Calculate 50% dimmed version of a color (used by ScannerUpdate)
|
||||
uint32_t NeoPatterns::DimColor(uint32_t color)
|
||||
{
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include <Adafruit_NeoPixel.h>
|
||||
|
||||
// Pattern types supported:
|
||||
enum pattern { NONE, RAINBOW_CYCLE, THEATER_CHASE, COLOR_WIPE, SCANNER, FADE };
|
||||
enum pattern { NONE, RAINBOW_CYCLE, THEATER_CHASE, COLOR_WIPE, SCANNER, FADE, RANDOM_FADE };
|
||||
// Patern directions supported:
|
||||
enum direction { FORWARD, REVERSE };
|
||||
|
||||
|
@ -20,10 +20,12 @@ void TheaterChase(uint32_t color1, uint32_t color2, uint8_t interval, direction
|
|||
void TheaterChaseUpdate();
|
||||
void ColorWipe(uint32_t color, uint8_t interval, direction dir = FORWARD);
|
||||
void ColorWipeUpdate();
|
||||
void Scanner(uint32_t color1, uint8_t interval);
|
||||
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();
|
||||
//Utilities
|
||||
void ColorSet(uint32_t color);
|
||||
uint8_t Red(uint32_t color);
|
||||
|
@ -44,6 +46,9 @@ 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
|
||||
|
|
|
@ -53,7 +53,10 @@ bool onSetEffect(const HomieRange& range, const String& value){
|
|||
String effect = value;
|
||||
effect.toLowerCase();
|
||||
if(effect == "scanner") {
|
||||
pixels.Scanner(pixels.Color(255,0,0), 55);
|
||||
pixels.Scanner(pixels.Color(255,0,0), 40);
|
||||
}
|
||||
else if(effect == "randomscanner") {
|
||||
pixels.Scanner(pixels.Color(255,0,0), 40,true);
|
||||
}
|
||||
else if(effect == "rainbowcycle") {
|
||||
pixels.RainbowCycle(50);
|
||||
|
@ -62,7 +65,10 @@ bool onSetEffect(const HomieRange& range, const String& value){
|
|||
pixels.TheaterChase(pixels.Color(0,0,255), pixels.Color(255,0,00), 100);
|
||||
}
|
||||
else if(effect == "fade") {
|
||||
pixels.Fade(pixels.Wheel(0),pixels.Wheel(255),pixels.Color(255,255,255),25);
|
||||
pixels.Fade(pixels.Color(100,0,0),pixels.Color(0,0,100),200,100);
|
||||
}
|
||||
else if(effect == "randomfade") {
|
||||
pixels.RandomFade();
|
||||
}
|
||||
else {
|
||||
pixels.None();
|
||||
|
|
Loading…
Reference in New Issue