Modes Timing Question!
I’m using the latest version of FastLED.
I want to automatically switch from one mode to the next at a certain time point in a song. I’ve been doing this with for() loops, but it’s kind of tricky and problematic since all the modes take a different amount of time to run:
void autoplaymode() {
for(int i=0; i<60; i++) {Rainbow();}
for(int i=0; i<10; i++) {Solid();}
for(int i=0; i<35; i++) {Gradient();}
…
Is there a better way to do this? I’m looking at the ChangeMe function in Andrew Tuline’s funkboxing update:
void ChangeMe()
{
uint8_t secondHand = (millis() / 10000) % 60;
static uint8_t lastSecond = 99;
if( lastSecond != secondHand) {
lastSecond = secondHand;
if (secondHand == 0) {twinkrun = 1; thisrot = 1; thiscutoff=254; STEPS=8;}
if (secondHand == 5) {thisrot = 0; thisdir=1;}
if (secondHand == 10) {HUE = 255;}
if (secondHand == 15) {twinkrun = 0;}
if (secondHand == 20) {STEPS = 16;}
}
Is there a way to use something like this to change modes? My main loop right now looks something like this:
void loop() {
switch (ledMode) {
case 999: break;
case 0: Rainbow(); break;
case 1: Solid(); break;
case 2: Gradient(); break;
…
And I’d love to have case 0 run at 0 seconds, case 1 at 5 seconds, case 2 at 10 seconds, etc. It seems like it should work but I must be missing something because it DOESN’T.
Here’s my attempt at the combined code… the modes play fine but when I click to case 3, no lights come on at all:
void loop() {
switch (ledMode) {
case 999: break;
case 0: Rainbow(); break;
case 1: Solid(); break;
case 2: Gradient(); break;
case 3: autoplaymode(); break;
}
}
void ChangeMode()
{
uint8_t secondHand = (millis() / 10000) % 60; // Increase this if you want a longer demo.
static uint8_t lastSecond = 99; // Static variable, means it’s only defined once. This is our ‘debounce’ variable.
if( lastSecond != secondHand) {
lastSecond = secondHand;
if (secondHand == 0) {Rainbow();}
if (secondHand == 5) {Solid();}
if (secondHand == 10) {Gradient();}
}
}
void autoplaymode()
{
ChangeMode();
show_at_max_brightness_for_power();
delay_at_max_brightness_for_power(loopdelay*2.5);
Serial.println(LEDS.getFPS());
}
Thanks so much for any advice!!
