Reputation: 1
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);
}
Upvotes: -1
Views: 40
Reputation: 131
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.
Upvotes: 0