Skip to content

Commit 6fef502

Browse files
committed
Simplify examples
1 parent bd45017 commit 6fef502

File tree

2 files changed

+19
-21
lines changed

2 files changed

+19
-21
lines changed

Diff for: examples/Standby_WakeFromPin/Standby_WakeFromPin.ino

+16-12
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,26 @@ volatile bool shouldGoToSleep = false;
3636
Board board;
3737

3838
void setup() {
39-
board = Board();
39+
pinMode(LED_BUILTIN, OUTPUT);
40+
41+
// Register the sleep and wake-up pins as inputs
42+
pinMode(GOTO_SLEEP_PIN, INPUT);
43+
pinMode(PORTENTA_C33_WAKEUP_PIN, INPUT);
44+
4045
board.begin();
41-
board.setAllPeripheralsPower(true); // TODO: Check if this is necessary
46+
board.setAllPeripheralsPower(true); // turn on peripherals after waking up from deep sleep
4247

4348
// Allows to use a button to put the device into sleep mode
44-
attachInterrupt(digitalPinToInterrupt(GOTO_SLEEP_PIN), goToSleep, RISING);
49+
attachInterrupt(digitalPinToInterrupt(GOTO_SLEEP_PIN), goToSleep, FALLING);
4550

4651
#if defined(ARDUINO_PORTENTA_C33)
4752
// On Portenta C33, you can specify which pin to use to wake up the device from sleep mode
4853
// Please read the documentation to understand which pins can be used to wake up the device.
49-
board.enableWakeupFromPin(PORTENTA_C33_WAKEUP_PIN, RISING);
54+
board.enableWakeupFromPin(PORTENTA_C33_WAKEUP_PIN, FALLING);
5055
#elif defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_GENERIC_STM32H747_M4) || defined(ARDUINO_NICLA_VISION)
5156
// On Portenta only pin GPIO0 can be used to wake up the device from sleep mode
5257
board.enableWakeupFromPin();
53-
#endif
54-
55-
pinMode(LEDB, OUTPUT);
58+
#endif
5659
}
5760

5861
void goToSleep(){
@@ -61,15 +64,16 @@ void goToSleep(){
6164

6265
void loop() {
6366
if(shouldGoToSleep){
64-
shouldGoToSleep = false;
67+
digitalWrite(LED_BUILTIN, HIGH); // turn off the LED to show that the board is going to sleep
6568
board.shutDownFuelGauge();
6669
board.setAllPeripheralsPower(false); // turn off peripherals before going to sleep
6770
board.standByUntilWakeupEvent();
71+
shouldGoToSleep = false;
6872
} else {
6973
// Show that the board is awake by blinking the LED
70-
digitalWrite(LEDB, HIGH);
71-
delay(1000);
72-
digitalWrite(LEDB, LOW);
73-
delay(1000);
74+
digitalWrite(LED_BUILTIN, HIGH);
75+
delay(500);
76+
digitalWrite(LED_BUILTIN, LOW);
77+
delay(500);
7478
}
7579
}

Diff for: examples/Standby_WakeFromRTC_C33/Standby_WakeFromRTC_C33.ino

+3-9
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include "Arduino_PowerManagement.h"
2222
#include "RTC.h"
2323

24-
RTCTime initialTime(1, Month::JANUARY, 2000, 12, 10, 00, DayOfWeek::TUESDAY, SaveLight::SAVING_TIME_ACTIVE);
24+
RTCTime initialTime(1, Month::JANUARY, 2000, 12, 10, 00, DayOfWeek::SATURDAY, SaveLight::SAVING_TIME_ACTIVE);
2525

2626
Board board;
2727

@@ -35,10 +35,6 @@ void blinkLed(int ledPin, int delayTime = 1000){
3535
void setup() {
3636
pinMode(LEDR, OUTPUT); // Used to indicate errors
3737
digitalWrite(LEDR, HIGH); // Turn off the red LED
38-
pinMode(LED_BUILTIN, OUTPUT);
39-
digitalWrite(LED_BUILTIN, LOW); // Turn on the built-in LED
40-
delay(1000);
41-
digitalWrite(LED_BUILTIN, HIGH); // Turn off the built-in LED
4238
pinMode(LEDB, OUTPUT); // Used to indicate that the board is awake
4339

4440
if(!board.begin()){
@@ -47,8 +43,7 @@ void setup() {
4743
}
4844
}
4945

50-
51-
board.setAllPeripheralsPower(true); // TODO: Check if this is necessary
46+
board.setAllPeripheralsPower(true);
5247
digitalWrite(LEDB, LOW); // Turn on the blue LED to show that the board is still awake
5348

5449
RTC.begin();
@@ -60,9 +55,8 @@ void setup() {
6055
}
6156
}
6257

63-
board.enableWakeupFromRTC(0, 0, 10); // Sleep for 10 seconds
64-
6558
delay(10000); // Keep the board awake for 10 seconds, so we can se it working
59+
board.enableWakeupFromRTC(0, 0, 10); // Sleep for 10 seconds
6660

6761
board.shutDownFuelGauge();
6862
board.setAllPeripheralsPower(false);

0 commit comments

Comments
 (0)