-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);
}
Antti29
  • 2,953
  • 12
  • 34
  • 36
  • Before you post a question here, you are supposed to do some research yourself. https://www.arduino.cc/en/Reference/Millis – gre_gor Sep 21 '17 at 16:54

1 Answers1

0

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.

KC Tucker
  • 131
  • 2
  • 4