Advertisement
NikWillOrStuff

dealing with rollover

Nov 30th, 2015
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.30 KB | None | 0 0
  1. void loop() {
  2.  
  3.   lastTime = currentTime
  4.   currentTime = micros()
  5.  
  6.   if (lastTime > currentTime)//if an overflow happened
  7.   {
  8.     if (lastTime % 4 != 0)
  9.     {
  10.       lastTime -= 10001;
  11.     }
  12.     else
  13.     {
  14.       lastTime += 10001;
  15.       currentTime += 10001;
  16.     }
  17.   }
  18.  
  19.   [code continues on]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement