1
1
/*
2
2
********************************************************************************
3
- * WakeFromGPIO.ino
4
3
*
5
4
* This example demonstrates how to wake up the Portenta C33 from deep sleep using a GPIO pin.
6
5
* The pin can be configured to wake up the device on a rising or falling edge, but not all pins are supported.
12
11
*
13
12
* The example also demonstrates how to use the PF1550 PMIC to turn off the peripherals
14
13
* before going to sleep and turn them back on after waking up.
15
- * uncomment #define TURN_PERIPHERALS_OFF on line 28 to enable this feature.
14
+ * uncomment #define TURN_PERIPHERALS_OFF on line 33 to enable this feature.
16
15
*
17
16
* When the device is not sleeping it will blink the built-in LED every 100ms.
18
17
*
31
30
#include " Arduino_LowPowerPortentaC33.h"
32
31
33
32
// #define TURN_PERIPHERALS_OFF
34
- #define SLEEP_PIN 0
35
- #define WAKE_PIN A3
33
+ #define SLEEP_PIN 0 // Pin used to put the device to sleep
34
+ #define WAKE_PIN A3 // Pin used to wake up the device
36
35
37
36
LowPower lowPower;
38
37
@@ -59,12 +58,16 @@ LowPower lowPower;
59
58
#endif
60
59
61
60
void goToSleep (){
62
- turnPeripheralsOff ();
61
+ #ifdef TURN_PERIPHERALS_OFF
62
+ turnPeripheralsOff ();
63
+ #endif
63
64
lowPower.deepSleep ();
64
65
}
65
66
66
67
void setup (){
67
68
lowPower = LowPower ();
69
+
70
+ // Register the callback function to put the device to sleep when the button is pressed
68
71
attachInterrupt (digitalPinToInterrupt (SLEEP_PIN), goToSleep, RISING);
69
72
lowPower.enableWakeupFromPin (WAKE_PIN, RISING);
70
73
pinMode (LED_BUILTIN, OUTPUT);
@@ -76,10 +79,11 @@ void setup(){
76
79
}
77
80
78
81
void loop (){
82
+ // Blink the built-in LED every 500ms when the device is not sleeping
79
83
digitalWrite (LED_BUILTIN, HIGH);
80
- delay (100 );
84
+ delay (500 );
81
85
digitalWrite (LED_BUILTIN, LOW);
82
- delay (100 );
86
+ delay (500 );
83
87
}
84
88
85
89
0 commit comments