I've been searching FastLED Google+ and googling elsewhere,

I’ve been searching FastLED Google+ and googling elsewhere, but can’t figure out how to run something in the void loop for a certain time, and then move on.

I suspect it has something to do with Every N Seconds, but I can’t piece anything together that works.

Following is a simple example of what I’m trying to do.

void loop() {
fadeToBlackBy( leds, NUM_LEDS, 5);
int i = random16(NUM_LEDS*24);
if ( i < NUM_LEDS ) {
leds[i] = CRGB::Blue;
}
FastLED.show();

RUN FOR SAY 30 SECONDS, AND THEN…

fadeToBlackBy( leds, NUM_LEDS, 5);
int i = random16(NUM_LEDS24);
if ( i < NUM_LEDS ) {
leds[i] = CRGB::Red; //RED
THIS IS THE PART THAT CHANGES
}
FastLED.show();

RUN FOR SAY 30 SECONDS (AND THEN VOID LOOP CONTINUES
}

If it makes it easier, I could also…

void loop() {

void effect01;

RUN XX SECONDS

void effect02;

RUN XX SECONDS

}

Even if someone could point me to a similar sample code, I don’t mind investing a couple more hours of trial and error. I just get the feeling I’m stumbling in the wrong direction right now.

Mark’s TimedPlaylist is a really nice way of doing this: https://gist.github.com/kriegsman/841c8cd66ed40c6ecaae

One option you could try is using a switch case and a timer to switch which case is being used every 30 seconds.
https://www.arduino.cc/en/Reference/SwitchCase

Okay… lots of ‘digital Greek’ to absorb!

I’ll start by modifying, adding, and deleting some stuff to the TimedPlaylist to better understand what does what. Then I can tweak it to suit (although I may keep most if not all of the included effects!).

I should also learn the switch case and timer concepts in case I need them later.

Thanks for pointing me in the right direction! I don’t mind learning by making mistakes – as long as they’re the correct mistakes. :wink:

Another semi-pre-fab way to do this is shown in the “TimecodePerformance” example here: https://gist.github.com/kriegsman/a916be18d32ec675fea8

How it works is a bit complicated, but using it as a skeleton for your own projects is pretty simple. The interesting part looks like this, with the timecode being specified as Hours,Minutes,Seconds.Millis :

FROM(0,0,00.100) { confetti(); }
FROM(0,0,01.500) { juggle(); }
FROM(0,0,03.375) { rainbowWithGlitter(); }
FROM(0,0,04.333) { bpm(); }
FROM(0,0,06.666) { juggle(); }
FROM(0,0,08.750) { confetti(); }
AT(0,0,12.000) { fill_solid(leds, NUM_LEDS, CRGB::Red); }
AT(0,0,15.000) { fill_solid(leds, NUM_LEDS, CRGB::Blue); }
FROM(0,0,16.500) { fadeToBlack(); }
FROM(0,0,18.000) { applause(); }

If you search the G+ archives for “performance” you’ll probably find some discussion about this. Again: how it works is a bit complicated, but using it is relatively easy. (The “FROM” macro ‘conceals a multitude of sins.’)

Yet another way involves elapsedMillis variables, which are a standard feature on Teensy and available as a library for all other Arduino boards. You create variables of type elapsedMillis, which work like normal 32 bit integers, but they automatically increment 1000 times per second. Then you can write code like this:

elapsedMillis mytime=0;

void loop() {
if (mytime < 2500) {
// do something for first 2.5 seconds
} else
if (mytime < 3500) {
// do something for next 1 second
} else {
mytime = 0; // set the time back to the beginning
}
}

You can create as many of these automatically incrementing variables as you need. Each is separately writable, so it’s easy to use others for timing various effects, as well as timeout for user inputs.

Hi @PaulStoffregen ,
was wondering how many other ‘standard features’ like that are available on the Teensy that I can’t see in the Arduino reference !?
Is there a list somewhere of these extra features ?

The good news? I’m surrounded by geniuses. The BETTER news? They’re all helpful!

Thanks everyone!

Hi again @PaulStoffregen , ignore my last question, looked into (was about time… :wink: the Teensyduino information in your PJRC website and finally discovered all I was missing using only the Arduino reference !!