Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save matthijskooijman/010515bf06e552c41472be0656bac62b to your computer and use it in GitHub Desktop.
Save matthijskooijman/010515bf06e552c41472be0656bac62b to your computer and use it in GitHub Desktop.
// This sleeps in powerdown mode for about the specified number of ms.
// If an interrupt occurs during sleep, it will be handled and sleep
// will continue (but up to 8 seconds of sleep might be "lost").
// START-DOSLEEP
void doSleep(uint32_t time) {
#if defined(DhtSend_ino)
DebugSerial.flush();
#endif
while (time > 0) {
// END-DOSLEEP
// This sleeps for at most time ms, or the minimum sleep time if
// that's more than time ms. Only some sleep times are available, so
// multiple sleeps might be needed.
// START-DOSLEEP
int slept;
if (time < 8000)
slept = Watchdog.sleep(time);
else
slept = Watchdog.sleep(8000);
if (slept >= time)
return;
time -= slept;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment