Buttons Widget and timer enable/disable

Hi, I’m having a hard time to figure out how to enable and disable a timer in my PGM on NodeMCU using a widget button.
I have several timers running but I want to enable and disable this one on demand with a button on blynk app and return the state to the Blynk app on Ipad.

timer.setInterval(AUTO_CTRL_TM*1000, autoControl);

I started with something like this but not getting anywhere.

BLYNK_WRITE(5) // AutoControl
{
int i=param.asInt();
if (i==1)
{
timer.disable(autoControl) = !timerstatus;

Thanks in advance

you have to keep the timer ID that is returned by timer.setinterval and pass that one to disable it.

Well, thanks for your quick answer.
Does the following code make sense?

timer.setInterval(AUTO_CTRL_TM*1000, autoControl);

I started with something like this but not getting anywhere.

BLYNK_WRITE(5) // AutoControl
{
int i=param.asInt();
if (i==1)
{
timer.disable(AUTO_CTRL_TM) = !timerstatus;
aplyCmd();
}

void aplyCmd()
{
if (timerstatus == 1)
{
Blynk.notify(“GBot: Warning ==>> AUTO ON”);
if (!turnOffOLED) displayData();
Auto.on();

}

Thanks!

thanks dale! im kinda a noob at c… i always wondered how to do this… and since the poster asked. i was kinda following along.

kibo… you might want to search for timer.disable… there are more examples than i can count.

Thanks but all examples I’m seeing are not working with Blynk.

All of them?.. like 100% of them?

image

The first 10 examples i looked at all worked with blynk just fine.

1 Like

@Kibonet when you post code on the forum you need to add backticks at the top and bottom of the code block so that it displays correctly.
This was explained in your welcome email and in the text that you deleted when you created this topic.

Please edit your two posts above that contain code (use the pencil icon at the bottom of each post to edit them’ and insert the backticks like this:
Blynk%20-%20FTFC

Thanks,

Pete.

No. :wink:

Note: The first argument of the timer.setInterval function is the interval in milliseconds … not the timer ID. As @DaleSchultz pointed out, the timer ID is returned by the timer.setInterval function,

int timerId = timer.setInterval(AUTO_CTRL_TM*1000, autoControl);

and,

timer.disable(timerId);

Refer to this,

Joe