kitesurfer1404/WS2812FX

play Effects one after the other

ddinternetagentur opened this issue · 4 comments

is it possible to play effects one after the other .. like an animation? would like to build an animation for opening and closing my garage.

To do this, of course, every animation would have to stop at some point ?

All White
Fade Out
Fade in RED
Larsonscanner RED
Fade out
Fade In White

or is it too time-consuming with this library?

The WS2812FX library isn't well suited to your project, since it doesn't provide functions to chain effects. It can be done, as mentioned in issue #127, but it's not pretty. You may have better luck, just using the base Adafruit_Neopixel library and implement the effect and state change code yourself.

Using the button code (I removed the button function, and threw in an automatic TIMER_MS function change), you could use the segmentation code, to not only tell it to do what you want above, but segment out specific parts as you do this...
I kind of see it like a fireworks show coded this way...

I agree I would like to see a simple fade function added to the ws2812library. Fade Color 1 to Color 2 + speed of the fade

(ugly code below, for something similar that worked),
something that could be added to the code below that would make it more friendly, would be a TIMER_MS integer table, or some sort of way you could add different time lengths for each of the specific cases instead of just a static time change variable

/*
Cycle through different patterns on Arduino Pro Mini ATMega328P (5V, 16MHz). 1000uF capacitor connected across VCC & GND of NeoPixel strip, and a 330ohm resistor in series with Data In and pin 6. Pin 2 pulled HIGH with button connected that pulls LOW when pressed.
*/

#include <WS2812FX.h>

#define LED_COUNT 98 // Number of WS2812B LEDs
#define LED_PIN 3 // Pin connected to Data In (DIN)
int showType = 0;

unsigned long patternInterval = 20; // time between steps in the pattern
unsigned long lastUpdate = 0; // for millis() when last update occurred
#define TIMER_MS 3000
unsigned long last_change = 0;
unsigned long now = 0;

WS2812FX ws2812fx = WS2812FX(LED_COUNT, LED_PIN, NEO_RGB + NEO_KHZ800);

void setup()
{

ws2812fx.init(); // Initialize WS2812FX library
ws2812fx.setBrightness(155); // Brightness 0-255 [black to blinding]
ws2812fx.setSpeed(2000); // Speed 10-5000 [fast to slow]
ws2812fx.setColor(BLACK); // Set the color of the LEDs
ws2812fx.start(); // Start WS2812FX library

}

void loop()
{

ws2812fx.service();

startShow(showType);

if(millis()- now > TIMER_MS){
showType++;
now = millis();
if (showType >= 47) // If case exceeds 46
{
showType = 0; // reset to case 0
}
}

}

void startShow(int showPattern)
{
switch (showPattern)
{

case 0:  ws2812fx.resetSegments();  ws2812fx.resetSegmentRuntimes();  
         ws2812fx.setSegment(0,0,97,FX_MODE_STATIC,GRAY,2000,false); 
        break;

case 1:  ws2812fx.resetSegments();  ws2812fx.resetSegmentRuntimes();  
         ws2812fx.setSegment(0,0,97,FX_MODE_STATIC,RED,2000,false); 
        break;
case 2: ws2812fx.resetSegments(); ws2812fx.resetSegmentRuntimes(); 
        ws2812fx.setSegment(0,0,97,FX_MODE_STATIC,WHITE,2000,false);
        break;
case 3: ws2812fx.resetSegments(); ws2812fx.resetSegmentRuntimes();
         ws2812fx.setSegment(0,0,97,FX_MODE_STATIC,RED,2000,false); 
        break;
case 4: ws2812fx.resetSegments(); ws2812fx.resetSegmentRuntimes(); 
        ws2812fx.setSegment(0,0,97,FX_MODE_STATIC,WHITE,2000,false);
        break;
case 5: ws2812fx.resetSegments();ws2812fx.resetSegmentRuntimes();
        ws2812fx.setSegment(0,0,97,FX_MODE_FIREWORKS,RED,2000,false);
        break;
case 6: ws2812fx.resetSegments();ws2812fx.resetSegmentRuntimes();
        ws2812fx.setSegment(0,0,97,FX_MODE_FLASH_SPARKLE,GRAY,2000,false);
        break;
case 7: ws2812fx.resetSegments();ws2812fx.resetSegmentRuntimes();
        ws2812fx.setSegment(0,0,97,FX_MODE_FIREWORKS,RED,500,false);
        break;
case 8: ws2812fx.resetSegments();ws2812fx.resetSegmentRuntimes();
        ws2812fx.setSegment(0, 0,      97,      FX_MODE_FIREWORKS,  WHITE,   1000, NO_OPTIONS);
        break;                                                       
case 9: ws2812fx.resetSegments();ws2812fx.resetSegmentRuntimes();
        ws2812fx.setSegment(0, 0,      97,      FX_MODE_STATIC,  RED,   2000, NO_OPTIONS);
        break;
case 10:ws2812fx.resetSegments();ws2812fx.resetSegmentRuntimes(); 
        ws2812fx.setSegment(0, 0,      97,      FX_MODE_STATIC,  GRAY,   400, NO_OPTIONS);
        break;
case 11: ws2812fx.resetSegments();  ws2812fx.resetSegmentRuntimes();  
         ws2812fx.setSegment(0,0,97,FX_MODE_STATIC,RED,2000,false); 
        break;
case 12: ws2812fx.resetSegments();  ws2812fx.resetSegmentRuntimes();  //All Grey
        ws2812fx.setSegment(0,0,97,FX_MODE_TWINKLE,RED,2000,false); 
        break;
case 13: ws2812fx.resetSegments();  ws2812fx.resetSegmentRuntimes();  //All Grey
         ws2812fx.setSegment(0,0,99,FX_MODE_TWINKLE,WHITE,8000,false); 
        break;
case 14: ws2812fx.resetSegments();  ws2812fx.resetSegmentRuntimes();  //All Grey
         ws2812fx.setSegment(0,0,99,FX_MODE_TWINKLE,WHITE,2000,false); 
        break;
case 15: ws2812fx.resetSegments();  ws2812fx.resetSegmentRuntimes();  //All Grey
         ws2812fx.setSegment(0,0,99,FX_MODE_TWINKLE,RED,1000,false); 

case 16: ws2812fx.resetSegments(); ws2812fx.resetSegmentRuntimes();
ws2812fx.setSegment(0, 0, 50, FX_MODE_STATIC, GRAY, 2000, NO_OPTIONS);
ws2812fx.setSegment(1, 51, 57, FX_MODE_STATIC, RED, 2000, NO_OPTIONS); //left eye (53-59)
ws2812fx.setSegment(2, 58, 63, FX_MODE_STATIC, GRAY, 2000, NO_OPTIONS);
ws2812fx.setSegment(3, 64, 70, FX_MODE_STATIC, RED, 2000, NO_OPTIONS); // right eye (66-72)
ws2812fx.setSegment(4, 71, 97, FX_MODE_STATIC, GRAY, 2000, NO_OPTIONS);
break;
case 17: ws2812fx.resetSegments(); ws2812fx.resetSegmentRuntimes();
ws2812fx.setSegment(0, 0, 50, FX_MODE_STATIC, GRAY, 2000, NO_OPTIONS);
ws2812fx.setSegment(1, 51, 57, FX_MODE_TWINKLE, RED, 1000, NO_OPTIONS); //left eye (53-59)
ws2812fx.setSegment(2, 58, 63, FX_MODE_STATIC, GRAY, 2000, NO_OPTIONS);
ws2812fx.setSegment(3, 64, 70, FX_MODE_TWINKLE, RED, 1000, NO_OPTIONS); // right eye (66-72)
ws2812fx.setSegment(4, 71, 97, FX_MODE_STATIC, GRAY, 2000, NO_OPTIONS);
break;
case 18: ws2812fx.resetSegments(); ws2812fx.resetSegmentRuntimes();
ws2812fx.setSegment(0, 0, 50, FX_MODE_STATIC, RED, 2000, NO_OPTIONS);
ws2812fx.setSegment(1, 51, 57, FX_MODE_TWINKLE, RED, 1000, NO_OPTIONS); //left eye (53-59)
ws2812fx.setSegment(2, 58, 63, FX_MODE_STATIC, RED, 2000, NO_OPTIONS);
ws2812fx.setSegment(3, 64, 70, FX_MODE_TWINKLE, RED, 1000, NO_OPTIONS); // right eye (66-72)
ws2812fx.setSegment(4, 71, 97, FX_MODE_STATIC, RED, 2000, NO_OPTIONS);
break;
case 19: ws2812fx.resetSegments(); ws2812fx.resetSegmentRuntimes();
ws2812fx.setSegment(0, 0, 99, FX_MODE_STATIC, PINK, 2000, NO_OPTIONS);
break;
case 20: ws2812fx.resetSegments(); ws2812fx.resetSegmentRuntimes();
ws2812fx.setSegment(0, 0, 99, FX_MODE_TWINKLE, PINK, 2000, NO_OPTIONS);
break;
case 21: ws2812fx.resetSegments(); ws2812fx.resetSegmentRuntimes();
ws2812fx.setSegment(0, 0, 99, FX_MODE_STATIC, PURPLE, 2000, NO_OPTIONS);
break;
case 22:ws2812fx.resetSegments(); ws2812fx.resetSegmentRuntimes();
ws2812fx.setSegment(0, 0, 99, FX_MODE_TWINKLE, PURPLE, 2000, NO_OPTIONS);
break;
case 23: ws2812fx.resetSegments(); ws2812fx.resetSegmentRuntimes();
ws2812fx.setSegment(0, 0, 99, FX_MODE_TWINKLE, WHITE, 2000, NO_OPTIONS);
break;
case 24: ws2812fx.resetSegments(); ws2812fx.resetSegmentRuntimes();
ws2812fx.setSegment(0, 0, 99, FX_MODE_STATIC, WHITE, 2000, NO_OPTIONS);
break;
case 25: ws2812fx.resetSegments(); ws2812fx.resetSegmentRuntimes();
ws2812fx.setSegment(0, 0, 99, FX_MODE_STATIC, RED, 2000, NO_OPTIONS);
break;
case 26: ws2812fx.resetSegments(); ws2812fx.resetSegmentRuntimes();
ws2812fx.setSegment(0, 0, 99, FX_MODE_TWINKLE, RED, 50, NO_OPTIONS);
break;
case 27: ws2812fx.resetSegments(); ws2812fx.resetSegmentRuntimes();
ws2812fx.setSegment(0, 0, 99, FX_MODE_STATIC, RED, 2000, NO_OPTIONS);
break;
case 28: ws2812fx.resetSegments(); ws2812fx.resetSegmentRuntimes();
ws2812fx.setSegment(0, 0, 99, FX_MODE_TWINKLE_RANDOM, RED, 4000, NO_OPTIONS);
break;
case 29: ws2812fx.resetSegments(); ws2812fx.resetSegmentRuntimes();
ws2812fx.setSegment(0, 0, 99, FX_MODE_SINGLE_DYNAMIC, GRAY, 1000, NO_OPTIONS);
break;

case 30: ws2812fx.resetSegments(); ws2812fx.resetSegmentRuntimes();
ws2812fx.setSegment(0, 0, 99, FX_MODE_SINGLE_DYNAMIC, RED, 8000, NO_OPTIONS);
break;

case 31: ws2812fx.resetSegments(); ws2812fx.resetSegmentRuntimes();
ws2812fx.setSegment(0, 0, 99, FX_MODE_FIREWORKS_RANDOM, RED, 2000, NO_OPTIONS);
break;
case 32: ws2812fx.resetSegments(); ws2812fx.resetSegmentRuntimes();
ws2812fx.setSegment(0, 0, 99, FX_MODE_STATIC, PURPLE, 200, NO_OPTIONS);
break;

case 33: ws2812fx.resetSegments(); ws2812fx.resetSegmentRuntimes();
ws2812fx.setSegment(0, 0, 99, FX_MODE_STATIC, GRAY, 2000, NO_OPTIONS);
break;

case 34: ws2812fx.resetSegments(); ws2812fx.resetSegmentRuntimes();
ws2812fx.setSegment(0, 0, 99, FX_MODE_FIREWORKS, RED, 200, NO_OPTIONS);
break;
case 35: ws2812fx.resetSegments(); ws2812fx.resetSegmentRuntimes();
ws2812fx.setSegment(0, 0, 99, FX_MODE_FIREWORKS, RED, 8000, NO_OPTIONS);
break;
case 36: ws2812fx.resetSegments(); ws2812fx.resetSegmentRuntimes();
ws2812fx.setSegment(0, 0, 99, FX_MODE_TWINKLE, RED, 5000, NO_OPTIONS);
break;
case 37: ws2812fx.resetSegments(); ws2812fx.resetSegmentRuntimes();
ws2812fx.setSegment(0, 0, 99, FX_MODE_HYPER_SPARKLE, RED, 1000, NO_OPTIONS);
break;
case 38: ws2812fx.resetSegments(); ws2812fx.resetSegmentRuntimes();
ws2812fx.setSegment(0, 0, 99, FX_MODE_HYPER_SPARKLE, GRAY, 1000, NO_OPTIONS);
break;

case 39: ws2812fx.resetSegments(); ws2812fx.resetSegmentRuntimes();
ws2812fx.setSegment(0, 0, 99, FX_MODE_STATIC, GRAY, 400, NO_OPTIONS);
break;

case 40: ws2812fx.resetSegments(); ws2812fx.resetSegmentRuntimes();
ws2812fx.setSegment(0, 0, 99, FX_MODE_STATIC, RED, 150, NO_OPTIONS);
break;

case 41: ws2812fx.resetSegments(); ws2812fx.resetSegmentRuntimes();
ws2812fx.setSegment(0, 0, 99, FX_MODE_SPARKLE, PURPLE, 150, NO_OPTIONS);
break;

case 42: ws2812fx.resetSegments(); ws2812fx.resetSegmentRuntimes();
ws2812fx.setSegment(0, 0, 50, FX_MODE_STATIC, PURPLE, 2000, NO_OPTIONS);
ws2812fx.setSegment(1, 51, 57, FX_MODE_TWINKLE, PURPLE, 2000, NO_OPTIONS); //left eye (53-59)
ws2812fx.setSegment(2, 58, 63, FX_MODE_STATIC, PURPLE, 2000, NO_OPTIONS);
ws2812fx.setSegment(3, 64, 70, FX_MODE_TWINKLE, PURPLE, 2000, NO_OPTIONS); // right eye (66-72)
ws2812fx.setSegment(4, 71, 97, FX_MODE_STATIC, PURPLE, 2000, NO_OPTIONS);
break;

case 43: ws2812fx.resetSegments(); ws2812fx.resetSegmentRuntimes();
ws2812fx.setSegment(0, 0, 97, FX_MODE_STATIC, BLACK, 2000, NO_OPTIONS);
break;

case 44: ws2812fx.resetSegments(); ws2812fx.resetSegmentRuntimes();
ws2812fx.setSegment(0, 0, 50, FX_MODE_FIREWORKS, RED, 2000, NO_OPTIONS);
ws2812fx.setSegment(1, 51, 57, FX_MODE_STATIC, RED, 2000, NO_OPTIONS); //left eye (53-59)
ws2812fx.setSegment(2, 58, 63, FX_MODE_FIREWORKS, RED, 2000, NO_OPTIONS);
ws2812fx.setSegment(3, 64, 70, FX_MODE_STATIC, RED, 2000, NO_OPTIONS); // right eye (66-72)
ws2812fx.setSegment(4, 71, 97, FX_MODE_FIREWORKS, RED, 2000, NO_OPTIONS);
break;
case 45: ws2812fx.resetSegments(); ws2812fx.resetSegmentRuntimes();
ws2812fx.setSegment(0, 0, 97, FX_MODE_STATIC, RED, 2000, NO_OPTIONS);
break;
case 46: ws2812fx.resetSegments(); ws2812fx.resetSegmentRuntimes();
ws2812fx.setSegment(0, 0, 97, FX_MODE_TWINKLE, RED, 2000, NO_OPTIONS);
break;

}
}

anywho you can get the just from the above code.

A static fade would be very usefull in the above coding style. Being able to fade from Color 1 to Color 2 and have it hold static. (with some sort of time fade variable, for a linear fade)
Other types of non linear fades would be neat as well

I have implemented some effect transition code in the latest v1.3.4 release, which allows you to fade from one effect to another. Please see the ws2812fx_transitions example sketch.