From 577499cccc3ed97da489568c382bd9c4d44af8ca Mon Sep 17 00:00:00 2001 From: Erick Ahmed Date: Thu, 1 May 2025 22:01:14 +0200 Subject: [PATCH] Implement 8 seconds watchdog --- main.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index 1388b6d..539704a 100644 --- a/main.c +++ b/main.c @@ -1,11 +1,34 @@ +#include + #define MOISTURE_SENSOR_A0 A0 +volatile bool readSensors = false; + +ISR(WDT_vect) { + readSensorsPtr = true; +} + +void watchdog() { + cli(); + // Set watchdog timer to 8 seconds + WDTCSR = (1 << WDCE) | (1 << WDE); + WDTCSR = (1 << WDIE) | (1 << WDP3); + sei(); +} + void setup() { pinMode(MOISTURE_SENSOR_A0, INPUT); Serial.begin(9600); } void loop() { - analogRead(MOISTURE_SENSOR_A0); - + if (readSensorsPtr) { + uint16_t moisture = analogRead(MOISTURE_SENSOR_A0); + Serial.println(moisture); + + readSensorsPtr = false; + } + + + }