Open
Description
Hi,
I am using a button to put Arduino in sleep mode and wake it up, but the Serial is not working anymore after it is waking up. What should I do?
#include "ArduinoLowPower.h"
volatile bool just_wakeup = true;
// Pin used to trigger a wakeup
const int pin = 0;
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
pinMode(pin, INPUT_PULLUP);
}
void loop() {
if (just_wakeup) {
just_wakeup = false;
delay(3000);
Serial.begin(115200);
}
digitalWrite(LED_BUILTIN, HIGH);
delay(500);
digitalWrite(LED_BUILTIN, LOW);
delay(500);
Serial.println("test");
if (digitalRead(pin) == LOW) {
Serial.end();
delay(500);
LowPower.attachInterruptWakeup(pin, wakeup_handler, FALLING );
LowPower.deepSleep();
}
}
void wakeup_handler() {
just_wakeup = true;
detachInterrupt(pin);
}