What is the function of "millis()" in this code snippet?

45 Views Asked by At

What is the function of millis() in this code snippet?

if (millis() > timer) {
    timer = millis() + 5000;
    ether.browseUrl(PSTR("/demo/"), "aphorisms.php", website, response_callback);
}
1

There are 1 best solutions below

0
On

The "timer" variable bumps the current cumulative time, as measured by millis(), and sets a value of 5 seconds greater. This snippet will reside in a larger loop, and whenever the time since the last iteration exceeds 5 seconds, will execute the subsequent statement and bump the timer again. Else, the snippet simply passes thru. If you wanted to do something every 5 seconds, or whatever interval you choose, this is a simple way to do that. Of course, that interval may be elongated, depending on other code in the loop.