Personally, I wouldn’t “turn off” (Enable/Disable or Toggle) a timer, it isn’t worth the effort.
Far better to use a flag which is checked at the beginning of each function that is called by a timer, as described in the “Overriding a Timer (auto/manual mode)” section of this topic…
If you do choose to go down the Enable/Disable or Toggle route then remember that you’ll need to create a dummy “sacrificial” timer in slot 0 to avoid issues with the SimpleTimer bug.
However, I don’t think I’d use either of these approaches.
Instead I’d have a single timer which calls a function that checks the current “mode” value, then calls the appropriate function from there.
Also, your variable names are very messy. I’d shop doing this:
because the relay1_state
name is very confusing. It’d not the state of Relay 1 until you update the relay1 GPIO to the appropriate status. At this stage it’s simply the mode1_button state, and that’s what you should call it.
If you need another variable to track the current state of relay1 then create one, but don’t re-use variables in the way you are.
The pseudo code would look like this…
BLYNK_WRITE(button1_vpin)
{
mode1_button = param.asInt();
Blynk.virtualWrite(button2_vpin,0); // Turn Button 2 off
Blynk.virtualWrite(button3_vpin,0); // Turn Button 3 off
// Update the other button variables to avoid confusion...
mode2_button = 0;
mode3_button = 0;
}
my_timed_loop
{
if(mode1_button==1)
{
\\ call the function that handles Mode 1
}
if(mode2_button==1)
{
\\ call the function that handles Mode 2
}
if(mode1_button==3)
{
\\ call the function that handles Mode 3
}
}
Pete.