Skip to content

Commit

Permalink
Simplify examples
Browse files Browse the repository at this point in the history
  • Loading branch information
sebromero committed Aug 21, 2024
1 parent bd45017 commit 6fef502
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
28 changes: 16 additions & 12 deletions examples/Standby_WakeFromPin/Standby_WakeFromPin.ino
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,26 @@ volatile bool shouldGoToSleep = false;
Board board;

void setup() {
board = Board();
pinMode(LED_BUILTIN, OUTPUT);

// Register the sleep and wake-up pins as inputs
pinMode(GOTO_SLEEP_PIN, INPUT);
pinMode(PORTENTA_C33_WAKEUP_PIN, INPUT);

board.begin();
board.setAllPeripheralsPower(true); // TODO: Check if this is necessary
board.setAllPeripheralsPower(true); // turn on peripherals after waking up from deep sleep

// Allows to use a button to put the device into sleep mode
attachInterrupt(digitalPinToInterrupt(GOTO_SLEEP_PIN), goToSleep, RISING);
attachInterrupt(digitalPinToInterrupt(GOTO_SLEEP_PIN), goToSleep, FALLING);

#if defined(ARDUINO_PORTENTA_C33)
// On Portenta C33, you can specify which pin to use to wake up the device from sleep mode
// Please read the documentation to understand which pins can be used to wake up the device.
board.enableWakeupFromPin(PORTENTA_C33_WAKEUP_PIN, RISING);
board.enableWakeupFromPin(PORTENTA_C33_WAKEUP_PIN, FALLING);
#elif defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_GENERIC_STM32H747_M4) || defined(ARDUINO_NICLA_VISION)
// On Portenta only pin GPIO0 can be used to wake up the device from sleep mode
board.enableWakeupFromPin();
#endif

pinMode(LEDB, OUTPUT);
#endif
}

void goToSleep(){
Expand All @@ -61,15 +64,16 @@ void goToSleep(){

void loop() {
if(shouldGoToSleep){
shouldGoToSleep = false;
digitalWrite(LED_BUILTIN, HIGH); // turn off the LED to show that the board is going to sleep
board.shutDownFuelGauge();
board.setAllPeripheralsPower(false); // turn off peripherals before going to sleep
board.standByUntilWakeupEvent();
shouldGoToSleep = false;
} else {
// Show that the board is awake by blinking the LED
digitalWrite(LEDB, HIGH);
delay(1000);
digitalWrite(LEDB, LOW);
delay(1000);
digitalWrite(LED_BUILTIN, HIGH);
delay(500);
digitalWrite(LED_BUILTIN, LOW);
delay(500);
}
}
12 changes: 3 additions & 9 deletions examples/Standby_WakeFromRTC_C33/Standby_WakeFromRTC_C33.ino
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "Arduino_PowerManagement.h"
#include "RTC.h"

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

Board board;

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

if(!board.begin()){
Expand All @@ -47,8 +43,7 @@ void setup() {
}
}


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

RTC.begin();
Expand All @@ -60,9 +55,8 @@ void setup() {
}
}

board.enableWakeupFromRTC(0, 0, 10); // Sleep for 10 seconds

delay(10000); // Keep the board awake for 10 seconds, so we can se it working
board.enableWakeupFromRTC(0, 0, 10); // Sleep for 10 seconds

board.shutDownFuelGauge();
board.setAllPeripheralsPower(false);
Expand Down

0 comments on commit 6fef502

Please sign in to comment.