daily pastebin goal
77%
SHARE
TWEET

Arduino: millis() rollover handling

baldengineer Jul 15th, 2012 3,776 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Created by James the Enginerd.
  2. // More information at:  http://www.cmiyc.com/blog/2012/07/16/arduino-how-do-you-reset-millis/
  3.  
  4. #define interval 1000
  5.  
  6. unsigned long waitUntil=0;
  7.  
  8. void setup() {
  9.   pinMode(13, OUTPUT);
  10. }
  11.  
  12. void loop() {
  13.   if ((unsigned long)(millis() - waitUntil) >= interval) {  // check for rollover
  14.     // It's time to do something!
  15.     digitalWrite(13, !digitalRead(13));  // Toggle the LED on Pin 13
  16.     waitUntil = waitUntil + interval;  // wait another interval cycle
  17.   }
  18. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top