Skip to content

Instantly share code, notes, and snippets.

@lcsjunior
Last active June 10, 2022 17:28
Show Gist options
  • Save lcsjunior/885e74adb530a96e65187de8f53768d9 to your computer and use it in GitHub Desktop.
Save lcsjunior/885e74adb530a96e65187de8f53768d9 to your computer and use it in GitHub Desktop.
// Globals
unsigned long previousMillis = 0;
const long eventInterval = 5000;
// ...
// Blocking "like delay()"
unsigned long start = millis();
while (millis() - start <= eventInterval) {
// ...
}
// Non-blocking
unsigned long currentMillis = millis();
// ...
if (currentMillis - previousMillis >= eventInterval) {
previousMillis = currentMillis;
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment