Using simpleTimer correctly?

if i want to run functions only sometimes, but not other times - do i set them up like this:

void warmLogic() 
{
timer.disable (coolLogicTimer); //turns off the other timer
do things; // read temps, send to Blynk, open vents etc
timer.enable (warmLogicTimer); // enables the 3 min timer to run this function every 3 mins
}

void coolLogic() 
{
timer.disable (warmLogicTimer); //turns off the other timer
dothings; // read temps, send to Blynk, open vents etc
timer.enable (coolLogicTimer); // enables the 3 min timer to run this function every 3 mins
}

void setup()
{
warmLogicTimer = timer.setTimeout(3L * 60000L, warmLogic); 
coolLogicTimer = timer.setTimeout(3L * 60000L, coolLogic); 
}

Yes that looks about right except you probably can’t enable a timer that is already enabled or disable a timer that isn’t enabled.

What I mean by this is you would need to enable or disable the timers in setup and ensure you know the sequence of which event will take place first in your sketch warmLogic or coolLogic.

You can enable/disable timers everywhere. It’s no problem at all. I use this stuff all the time to set different timers and enable/disable them :slight_smile:

The SimpleTimer library also has functions to see wether a timer is enabled or disabled, if you want to know for sure. The reference on arduino.cc is quite elaborate.

So any time I call timer.enable the time out starts counting?

I’ve tried this and after a few days it stops working like it is supposed to.

I only have 10 separate timers set up in the void setup() but I thought maybe the 10 timer limit might be my issue?

In the meantime I am just running interval timers to run the logic functions and setting flags to ignore them if another function is running…

But because I’m going to combine two of my sketches into a mega sketch with 20 functions, and need to nail down my simpletimer practices…

Yes enable starts the timer countdown. You can have more than 10 timers but you need a second instance (new timer name) for the second set of 10 timers.

I already have 10 individually named timers…

What Costas means, you can declare more timer instances e.g.:

SimpleTimer timer1
SimpleTimer timer2

And each can have 10 named timers.

1 Like

hole

eeeh

kraap!!!

:astonished:

1 Like