Skip to content

Instantly share code, notes, and snippets.

@stonehippo
Created November 23, 2021 13:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stonehippo/9667aed25fc45b7f42f17b79e7287bd3 to your computer and use it in GitHub Desktop.
Save stonehippo/9667aed25fc45b7f42f17b79e7287bd3 to your computer and use it in GitHub Desktop.
A trivial Arduino application showing delaying an event synchronously for some number of minutes
#define SECOND 1000 // 1 sec = 1000 millseconds
#define MINUTE 60 * SECOND // 60 sec = 1 minute
void setup() {
Serial.begin(115200);
randomSeed(analogRead(0)); // choose a pseudo-random starting seed
}
void loop() {
WaitForNMinutes();
}
void WaitForNMinutes() {
long minutes = random(1,60); // generate a value between 1 and 60, inclusive
Serial.print("Waiting for "); Serial.print(minutes); Serial.println(" minutes");
delay(minutes * MINUTE);
Serial.println("Ok, done waiting!");
Serial.println("-----");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment