Skip to content

Instantly share code, notes, and snippets.

@nullstalgia
Forked from robbinsrush/sketch.ino
Created February 18, 2020 09:42
Show Gist options
  • Save nullstalgia/059b98656a85c8821e988ccac51a62cf to your computer and use it in GitHub Desktop.
Save nullstalgia/059b98656a85c8821e988ccac51a62cf to your computer and use it in GitHub Desktop.
#include <avr/sleep.h>
#include <avr/wdt.h>
volatile bool wdtFired;
// watchdog interrupt
ISR (WDT_vect)
{
wdt_disable(); // disable watchdog
wdtFired = true;
} // end of WDT_vect
void setup ()
{
noInterrupts (); // timed sequence follows
MCUSR = 0;
// allow changes, disable reset
WDTCSR = bit (WDCE) | bit (WDE);
// set interrupt mode and an interval
WDTCSR = bit (WDIE); // set WDIE, and 16 ms seconds delay
wdt_reset(); // pat the dog
wdtFired = false;
interrupts ();
unsigned long startTime = micros ();
while (!wdtFired)
{ } // wait for watchdog
unsigned long endTime = micros ();
Serial.begin (115200);
Serial.println ();
Serial.print (F("Time taken = "));
Serial.println (endTime - startTime);
}
void loop () { }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment