Add sleep function to enable power down mode

This commit is contained in:
2025-05-01 22:23:49 +02:00
committed by erickahmed
parent 577499cccc
commit 02a6541647
+11 -6
View File
@@ -5,7 +5,7 @@
volatile bool readSensors = false;
ISR(WDT_vect) {
readSensorsPtr = true;
readSensors = true;
}
void watchdog() {
@@ -16,19 +16,24 @@ void watchdog() {
sei();
}
void sleep_mode() {
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable();
sleep_cpu();
sleep_disable();
}
void setup() {
pinMode(MOISTURE_SENSOR_A0, INPUT);
Serial.begin(9600);
}
void loop() {
if (readSensorsPtr) {
if (readSensors) {
uint16_t moisture = analogRead(MOISTURE_SENSOR_A0);
Serial.println(moisture);
readSensorsPtr = false;
readSensors = false;
}
sleep_mode();
}