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; + } + + + }