timer.setInterval() & timer.setTimeout()

I’m a little unsure of how these two functions work together and the overall process time of my loop when I combine them.

In setup I have

timer.setInterval(1000L, myfunction1)

then inside myfunction1 I have

timer.setTimeout(1000L, myfunction2)

in myfunction2 I have

timer.setTimeout(1000L, myfunction3)

This process occurs 2 more times.

So my question is , Does my overall loop process time take 5 seconds to complete ?

Why not find out for yourself by adding some Serial.print statements to your code that tells you when the various timers are being triggered. You can use the timestamp option in the serial monitor to give you the timings, or add a Serial.print of the current millis() value if you prefer.

If you want to learn more about how the Blynk timer works then read the Simple Timer documentation here (Blynk Timer is a slightly improved version of Simple Timer, but the same documentation applies):
https://playground.arduino.cc/Code/SimpleTimer/

You’ll probably see that there is other functionality that maybe a simpler/neater way of achieving what you want.

Pete.

1 Like

Once again you give a timely response and your advice is spot on
Thank You Pete

1 Like

So now I see the functions are all called after 1 second on each loop and the loop process is busy for less than one second.

Are you doing it this way to prevent Blynk disconnects that occur if you put everything in one function?

Pete.

Yes , if I did it without the interval the hardware and app disconnect continuously.

Most of the functions do a virtualWite

The solution to that is to add some Blynk.run() commands within your function, to allow the Blynk library to grab a bit of processor time and do its background housekeeping.
If you add these at the points where you are currently triggering the timers to call the next block of code then it should be fine.
If you’re doing a large block of virtualWrites then scatter a few Blynk.run() command into these blocks to allow Blynk to come up for air.

Blynk.run()

This function should be called frequently to process incoming commands and perform housekeeping of Blynk connection. It is usually called in void loop() {} .

This command can be initiated it in other places of your code unless you run out of heap memory (in the cascaded functions with local memory).

For example, it is not recommended to call Blynk.run() inside of the BLYNK_READ and BLYNK_WRITE functions on low-RAM devices.

https://docs.blynk.cc/#blynk-firmware-connection-management-blynkrun

Pete.

3 Likes

Thats good to know Pete, originally I came with the disconnect problem and the interval was the only solution presented to me so I went with it .
Seems more straight forward to just do the blynk.run() within the functions .

I’m gonna make a version 2 this way to test it out . The current project is due for submission the coming week so I will leave that as it is because my schedule is swamped .

Thanks again for all your support .

Ed.

Hi Ed,
Could you be so kind to share your code, I have a similar problem and would like to see other way of doing it.
Thanks
Y3G

It’s about 18 months since Ed visited the forum, so you may not get an answer from him.

It might be better if you start a new topic, state whether you are using Blynk Legacy or Blynk IoT, and share your code and a full description of the problem(s) you are encountering.

If you came to this topic because of its title then you may want to read this topic, which I’ve written since…

Pete.

1 Like