Skip to content

Commit d38648a

Browse files
committed
Avoid PMIC interaction in interrupt handler
1 parent 9c979bc commit d38648a

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

examples/WakeFromPin/WakeFromPin.ino

+13-7
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#define WAKE_PIN A3 // Pin used to wake up the device
3333

3434
LowPower lowPower;
35+
bool shouldSleep = false;
3536

3637
#ifdef TURN_PERIPHERALS_OFF
3738
#include "Arduino_PMIC.h"
@@ -56,13 +57,7 @@ LowPower lowPower;
5657
#endif
5758

5859
void goToSleep(){
59-
// Turn off the built-in LED before going to sleep
60-
digitalWrite(LED_BUILTIN, HIGH);
61-
62-
#ifdef TURN_PERIPHERALS_OFF
63-
turnPeripheralsOff();
64-
#endif
65-
lowPower.deepSleep();
60+
shouldSleep = true;
6661
}
6762

6863
void setup(){
@@ -83,6 +78,17 @@ void setup(){
8378
}
8479

8580
void loop(){
81+
if(shouldSleep){
82+
// Turn off the built-in LED before going to sleep
83+
digitalWrite(LED_BUILTIN, HIGH);
84+
85+
#ifdef TURN_PERIPHERALS_OFF
86+
turnPeripheralsOff();
87+
#endif
88+
lowPower.deepSleep();
89+
shouldSleep = false;
90+
}
91+
8692
// Blink the built-in LED every 500ms when the device is not sleeping
8793
digitalWrite(LED_BUILTIN, LOW);
8894
delay(500);

0 commit comments

Comments
 (0)