Skip to content

Commit 9b0f754

Browse files
committed
Refactor example
1 parent 09e81a4 commit 9b0f754

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

examples/DeepSleep_WakeFromPin/DeepSleep_WakeFromPin.ino

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,52 @@
44

55

66
#define WAKE_PIN A3
7-
#define SLEEP_PIN 0
7+
#define GOTO_SLEEP_PIN 0
88

9-
volatile bool sleepFlag = false;
9+
volatile bool shouldGoToSleep = false;
1010

11-
PowerManagement manager;
1211
Board board;
1312
Charger charger;
1413

1514
void setup() {
15+
board = Board();
16+
charger = Charger();
17+
board.begin();
18+
charger.begin();
1619

17-
18-
19-
manager = PowerManagement();
20-
manager.begin();
21-
board = manager.getBoard();
22-
charger = manager.getCharger();
23-
24-
attachInterrupt(digitalPinToInterrupt(SLEEP_PIN), goToSleep, RISING);
20+
// Allows to use a button to put the device into sleep mode
21+
attachInterrupt(digitalPinToInterrupt(GOTO_SLEEP_PIN), goToSleep, RISING);
2522

2623
#if defined(ARDUINO_PORTENTA_C33)
27-
board.enableWakeupFromPin(WAKE_PIN, RISING);
24+
// On Portenta C33, you can specify which pin to use to wake up the device from sleep mode
25+
// Please read the documentation to understand which pins can be used to wake up the device.
26+
board.enableWakeupFromPin(WAKE_UP_PIN, RISING);
2827
#elif defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_NICLA_VISION)
28+
// On Portenta only pin GPIO0 can be used to wake up the device from sleep mode
2929
board.enableWakeupFromPin();
3030
#endif
3131

32-
32+
// TODO why is this needed? Why true?
3333
board.setAllPeripheralsPower(true);
34-
charger.disable();
34+
// TODO why is this needed?
35+
charger.setEnabled(false);
3536

3637
pinMode(LEDB, OUTPUT);
3738
}
3839

3940
void goToSleep(){
40-
sleepFlag = true;
41+
shouldGoToSleep = true;
4142
}
4243

4344
void loop() {
44-
if(sleepFlag){
45-
sleepFlag = false;
45+
if(shouldGoToSleep){
46+
shouldGoToSleep = false;
4647

48+
// TODO why is this here?
4749
//board.setAllPeripheralsPower(false);
4850
board.standByUntilWakeupEvent();
4951
} else {
50-
52+
// Show that the board is awake by blinking the LED
5153
digitalWrite(LEDB, HIGH);
5254
delay(1000);
5355
digitalWrite(LEDB, LOW);

0 commit comments

Comments
 (0)