Last active
January 3, 2019 08:19
-
-
Save dirkjanfaber/1a80a73c491b6f8da9b7ec2047f4d7ea to your computer and use it in GitHub Desktop.
A watchdog timer for ESP8266 (or just the Arduino). Based on the code of https://www.youtube.com/watch?v=D_7ciW_TCac
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
#include <Ticker.h> | |
Ticker secondTick; | |
#define debug 1 | |
volatile int watchdogCount = 0; | |
void ISRwatchdog() { | |
watchdogCount++; | |
if ( watchdogCount == 5 ) { | |
// Only print to serial when debugging | |
(debug) && Serial.println("The dog bites!"); | |
ESP.reset(); | |
} | |
} | |
void setup() { | |
Serial.begin(115200); | |
Serial.println("Starting"); | |
secondTick.attach(1, ISRwatchdog); | |
} | |
void loop() { | |
Serial.print("Watchdog counter = "); | |
Serial.println(watchdogCount); | |
// Feeding the dog | |
watchdogCount = 0; | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment