Should I use EVERY_N_MILLISECONDS ?

Should I use EVERY_N_MILLISECONDS ?

I figured out how to get a comet effect to start at one end of a strip and move to the other end.

I know how to start an effect with a bunch of those comets already in place and then start animating them to travel down the strip.

What I’d like to do is have a comet start its journey, and then have another comet(s) start based on a time interval. Maybe I’ll let the first comet make it to the end, or maybe I’ll rapid-fire a bunch of them. But I don’t want them to show up on the strip unless they’ve “emerged” from the start of the strip.

I don’t mind a lot of trial and error learning while playing with the code… I’m just looking for the right place to start. The longer I struggle with it, the better I’ll understand it once I figure it out. :slight_smile:

So… can I use EVERY_N_MILLISECONDS to launch something like the following at whatever interval I choose? Again, you don’t have to write any code for me. Just wondering if I’m going in the right or wrong direction. Thanks!

for(int i = 0; i < NUM_LEDS_PER_STRIP; i++)
{
//
leds[i] = CHSV( 0, 255, 255);
leds[i-1] = CHSV(0,255,200);
leds[i-2] = CHSV(0,255,175);
leds[i-3] = CHSV(0,255,125);
leds[i-4] = CHSV(0,255,75);
leds[i-5] = CHSV(0,255,25);
leds[i-6] = CHSV(0,255,10);
leds[i-7] = CHSV(0,255,10);
leds[i-8] = CHSV(0,255,10);
//
delay(3); // Determines speed of comet
//
FastLED.show();

I’ve been replacing my for loops with EVERY_N_MILLISECONDS to have less blocking code and not need to use delays. You can have multiple EVERY_N_MILLISECONDS in your code and have them work just fine. Just remember that for loops and delays will mess with the timing so it is best to not use them. I believe Mark wrote the code for the timers and said he’s had up to ~20 running at a time without issue. You can get fancy and even be able to change the number of milliseconds by using EVERY_N_MILLISECONDS_I . If you search you can find out how to use it.

@Brian - EVERY_N_MILLISECONDS is indeed awesome. Additionally, I use sine waves instead of counting pixels up and down a strip. It take a bit more brainpower and a LOT less code.

In the meantime, this old ‘Matrix’ one could be modified to support comets:

Thank you gentlemen! I look forward to many hours of frustrating fun!

@Andrew_Tuline sine waves are a whole other ball o’ wax! I’ll either need an overly-commented example or a dummies guide… so I’ll set that aside for much later. Definitely planning on tackling it though. Seems like a tool that can solve a lot of problems once I learn which end to hold.