New randomscanner and randomfade effect

This commit is contained in:
Juergen Jung 2017-02-17 03:49:22 +01:00
parent 0a4eda713d
commit 7673b4e19c
3 changed files with 42 additions and 5 deletions

View File

@ -27,6 +27,9 @@ void NeoPatterns::Update(){
case FADE: case FADE:
FadeUpdate(); FadeUpdate();
break; break;
case RANDOM_FADE:
RandomFadeUpdate();
break;
case NONE: case NONE:
break; break;
default: default:
@ -146,18 +149,29 @@ void NeoPatterns::ColorWipeUpdate()
} }
// Initialize for a SCANNNER // 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; ActivePattern = SCANNER;
Interval = interval; Interval = interval;
TotalSteps = (numPixels() - 1) * 2; TotalSteps = (numPixels() - 1) * 2;
Color1 = color1; Color1 = color1;
Index = 0; Index = 0;
wPos = 0;
this->colorful = colorful;
} }
// Update the Scanner Pattern // Update the Scanner Pattern
void NeoPatterns::ScannerUpdate() void NeoPatterns::ScannerUpdate()
{ {
if(colorful) {
Color1 = Wheel(wPos);
if(wPos >= 255) {
wPos =0;
}
else {
wPos++;
}
}
for (int i = 0; i < numPixels(); i++) for (int i = 0; i < numPixels(); i++)
{ {
if (i == Index) // Scan Pixel to the right if (i == Index) // Scan Pixel to the right
@ -175,6 +189,7 @@ void NeoPatterns::ScannerUpdate()
} }
show(); show();
Increment(); Increment();
} }
void NeoPatterns::Fade(uint32_t color1, uint32_t color2, uint16_t steps, uint8_t interval, direction dir) 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(); 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) // Calculate 50% dimmed version of a color (used by ScannerUpdate)
uint32_t NeoPatterns::DimColor(uint32_t color) uint32_t NeoPatterns::DimColor(uint32_t color)
{ {

View File

@ -1,7 +1,7 @@
#include <Adafruit_NeoPixel.h> #include <Adafruit_NeoPixel.h>
// Pattern types supported: // 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: // Patern directions supported:
enum direction { FORWARD, REVERSE }; enum direction { FORWARD, REVERSE };
@ -20,10 +20,12 @@ void TheaterChase(uint32_t color1, uint32_t color2, uint8_t interval, direction
void TheaterChaseUpdate(); void TheaterChaseUpdate();
void ColorWipe(uint32_t color, uint8_t interval, direction dir = FORWARD); void ColorWipe(uint32_t color, uint8_t interval, direction dir = FORWARD);
void ColorWipeUpdate(); 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 ScannerUpdate();
void Fade(uint32_t color1, uint32_t color2, uint16_t steps, uint8_t interval, direction dir = FORWARD); void Fade(uint32_t color1, uint32_t color2, uint16_t steps, uint8_t interval, direction dir = FORWARD);
void FadeUpdate(); void FadeUpdate();
void RandomFade(uint8_t interval = 100);
void RandomFadeUpdate();
//Utilities //Utilities
void ColorSet(uint32_t color); void ColorSet(uint32_t color);
uint8_t Red(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 TotalSteps; // total number of steps in the pattern
uint16_t Index; // current step within the pattern uint16_t Index; // current step within the pattern
byte wPos;
bool colorful;
uint32_t DimColor(uint32_t color); uint32_t DimColor(uint32_t color);
void Increment(); void Increment();
void (*OnComplete)(); // Callback on completion of pattern void (*OnComplete)(); // Callback on completion of pattern

View File

@ -53,7 +53,10 @@ bool onSetEffect(const HomieRange& range, const String& value){
String effect = value; String effect = value;
effect.toLowerCase(); effect.toLowerCase();
if(effect == "scanner") { 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") { else if(effect == "rainbowcycle") {
pixels.RainbowCycle(50); 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); pixels.TheaterChase(pixels.Color(0,0,255), pixels.Color(255,0,00), 100);
} }
else if(effect == "fade") { 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 { else {
pixels.None(); pixels.None();