Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • 2
    Your MILLIS_OVERFLOW is wrong. On recent versions of the Arduino library, millis() overflows at 2^32 (49.7 days), which means that testing for the overflow is useless. Commented May 10, 2015 at 12:27
  • Didn't know, thanks! i updated the constant MILLIS_OVERFLOW. (it's a digital clock, testing for the overflow isn't useless). Anyway, i think that the proposed solution by @23ars using Timer Interrupts is better than mine. Commented May 11, 2015 at 14:03
  • This code is still incorrect. Testing for the overflow is definitely useless: per the rules of modular arithmetic, which are guaranteed for unsigned numbers by the C and C++ languages, currentMillis - previousMillis will always yield the right answer, regardless of overflows. Commented May 11, 2015 at 15:05
  • @EdgarBonet sorry, but i don't get it. Did you test this code on Arduino? Please could you explain how this code should work without testing for the overflow. Thanks! Commented May 11, 2015 at 19:39
  • 2
    I tested it right now. When millis() overflows, it goes like crazy changing the time at each loop iteration. If you remove the test for the overflow, it works just fine. If you read carefully the liked article on modular arithmetic, it should be obvious that the test is useless. Commented May 11, 2015 at 20:02