Created
May 10, 2014 20:03
-
-
Save vivithemage/f70b39fd966984d9cf66 to your computer and use it in GitHub Desktop.
arduino working delay - do things while delay is called rather than wait.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Used instead of delay so various things can still be checked (e.g. button presses, saving data). | |
int workingDelay(int interval) { | |
unsigned long previousMillis = millis(); | |
while(true) { | |
unsigned long currentMillis = millis(); | |
Serial.println(currentMillis); | |
// If the current miliseconds run is more than the interval, the delay has been done, so exit. | |
if(currentMillis - previousMillis > interval) { | |
return 0; | |
} else { | |
// running during delay | |
int randNum1 = random(300); | |
int randNum2 = random(300); | |
int randNumSum = randNum1 + randNum2; | |
Serial.println("Sum result:"); | |
Serial.println(randNumSum); | |
// end running during delay | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment