@@ -36,23 +36,26 @@ volatile bool shouldGoToSleep = false;
36
36
Board board;
37
37
38
38
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
+
40
45
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
42
47
43
48
// 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 );
45
50
46
51
#if defined(ARDUINO_PORTENTA_C33)
47
52
// On Portenta C33, you can specify which pin to use to wake up the device from sleep mode
48
53
// 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 );
50
55
#elif defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_GENERIC_STM32H747_M4) || defined(ARDUINO_NICLA_VISION)
51
56
// On Portenta only pin GPIO0 can be used to wake up the device from sleep mode
52
57
board.enableWakeupFromPin ();
53
- #endif
54
-
55
- pinMode (LEDB, OUTPUT);
58
+ #endif
56
59
}
57
60
58
61
void goToSleep (){
@@ -61,15 +64,16 @@ void goToSleep(){
61
64
62
65
void loop () {
63
66
if (shouldGoToSleep){
64
- shouldGoToSleep = false ;
67
+ digitalWrite (LED_BUILTIN, HIGH); // turn off the LED to show that the board is going to sleep
65
68
board.shutDownFuelGauge ();
66
69
board.setAllPeripheralsPower (false ); // turn off peripherals before going to sleep
67
70
board.standByUntilWakeupEvent ();
71
+ shouldGoToSleep = false ;
68
72
} else {
69
73
// 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 );
74
78
}
75
79
}
0 commit comments