Holiday Light Sequential Timer

Hello all,

I'm currently working on a holiday light project at home and have run into an issue with my less than basic knowledge of arduino programming. I'm fluent in PLC programming however most of which doesn't seem to translate haha.

I have already installed and tested all of my strips and have some animations currently running. (love this btw). However i am now starting to attempt to create my own light show and just dont understand how timers work in this environment.

My goal is to learn how to set up a timer with a predetermined value (lets say 5 minutes). And be able to set different flags at within the 5 minute timer. After the timer has completed it will start over again. I have provided a small piece of code using a test strip of 67 LEDs and 2 animations. (they are the same with different colors. (this is just for testing and will use different animations as i get more creative.

If someone could please help me better understand what i am trying to accomplish that would be awesome! Thanks in advance!!!

#include <FastLED.h>

#define LED_PIN     5
#define NUM_LEDS    67
#define BRIGHTNESS  100
#define LED_TYPE    WS2812B
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];

void setup() {
  FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS );
}
  
void loop(){  
   
?????????????  Sequential Timer to run different animations here  ????????????????
    
  #if ??????????????
  
    fadeToBlackBy( leds, NUM_LEDS, 30);
    int pos1a = beatsin8( 16, 0, 67 );         
      leds[0+pos1a]   = CRGB:: Blue;
      leds[67-pos1a]   = CRGB:: Red;}
  #endif
  
  #if ???????????????
  
    fadeToBlackBy( leds, NUM_LEDS, 30);
    int pos1a = beatsin8( 100, 0, 67 ); 
      leds[0+pos1a]   = CRGB:: Green;
      leds[67-pos1a]   = CRGB:: Orange;
  #endif
      FastLED.show();

Im sure youre expecting a more explicit response, but i use a very very basic derivate of the LED "blink without delay" function. You can find many examples, codes and tutorials to that online, with your programming language im sure you can quickly adapt it to fit.....hope to have gotten you started out right, if not ill post an example tomorrow

Ive looked through that example a few times. Im going to keep reading it too lol. Im just struggling with translating it to something i can understand haha. Thanks for you input!!

if (millis() - previousMillis >= interval) {
    previousMillis = millis();
    //Code whatever needs to be done

In the setup i set previousMillis=millis() and define the interval. In your case pretty high, as 5 minutes has quite a few millis in them :wink:

During each loop i compare if the time elapsed is smaller or greater than the threshold. First time reaching the threshold i reset the counter, and within the same if clause run whatever i need to run after that interval.....in your case the code youve posted already

Im starting to understand the blink without delay code, but on second thought the overall timer may not be the right way to go about this. Would it make more sense to cascade different timers so i could run different animations back to back with out having to adjust the full duration timer?

That depends on what exactly you want to accomplish. Youve kept that secret so far.....so the answer is a clear noyesmaybe

My apologies i thought my original post was more clear. I have installed led strips (ws2812B) on my house in lou of christmas lights. I have been able to write single animations to make the lights bounce or move or whatnot.

I do not know how to cycle thorugh several different animations for a predetermined amount of time.

ie: animation 1 runs for 10 sec, animation 2 runs for 10 sec, animation 3 runs for 15, sec.

I also am trying to look at this with an open mind. Hence my previous post....IDK if it makes sense to use 1 timer with separate set points for each animation or have a separate timer for each animation that cascades from one to the next. Nor do i totally understand exactly how to code either example.

I have dome similar, although i have just 2 different functions, one fading random star, and one dropping random comets.....they are overlayed, and a subroutine picks the brighter choice in case the 2 functions are overlayed. All are working with the blink without delay code, combined with a random() function for the delay time.

Still not sure what effects you want to accomplish, but changing one effect to another can be done easily by creating different functions (void()) for the different effects, and then running them for either predefined times, or random times.....

Look in the fastLED Example file "DemoReel100". It has code that cycles through various patterns. Each pattern is in its own function, so you can add your own functions to it.

There is a neat non-blocking timer in the fastLED library that the DemoReel100 example uses:

EVERY_N_SECONDS(n){
  // Do something every n seconds
  // You can set a flag, bump a counter, run a function, 
  // or as in the example sketch, bump a pointer to 
  //  the next function to run.
}

EVERY_N is a preprocessor macro which is replaced by a block of code when compiled. It is a very convoluted bit of preprocessing code that is difficult (even for experts) to follow through with lots of concatenations and multiple layers of definition, so my advice is don't worry, just use it. If you want to try and decipher it all it's in the file lib8tion.h in the FastLED library

Hope this helps.