Skip to content

Commit ba56977

Browse files
committed
Add SW0 button interrupt
1 parent 6f5c896 commit ba56977

File tree

1 file changed

+36
-7
lines changed

1 file changed

+36
-7
lines changed

src/examples/low_power/low_power.ino

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,31 @@
2020
#endif
2121
#endif
2222

23-
void setup() {
23+
#define SW0 PIN_PD2
2424

25+
ISR(PORTD_PORT_vect) {
26+
if (PORTD.INTFLAGS & PIN2_bm) {
27+
PORTD.INTFLAGS = PIN2_bm;
28+
}
29+
}
30+
31+
void setup() {
2532
Log.begin(115200);
33+
Log.setLogLevel(LogLevel::DEBUG);
2634

2735
LedCtrl.begin();
2836
LedCtrl.startupCycle();
2937

38+
// Configure SW0 for interrupt so we can wake the device up from sleep by
39+
// pressing the button
40+
pinConfigure(SW0, PIN_DIR_INPUT | PIN_INT_FALL);
41+
3042
// Configure the power save configuration, start the LTE modem and wait
3143
// until we are connected to the operator
3244
//
33-
// Here we say that we want to sleep for 30 seconds * 2 = 60 seconds each
45+
// Here we say that we want to sleep for 30 seconds * 3 = 90 seconds each
3446
// time we invoke sleep
35-
LowPower.begin(SleepMultiplier::THIRTY_SECONDS, 2, SleepMode::REGULAR);
47+
LowPower.begin(SleepMultiplier::ONE_MINUTE, 3, SleepMode::REGULAR);
3648
Lte.begin();
3749
Log.infof("Connecting to operator");
3850
while (!Lte.isConnected()) {
@@ -45,14 +57,31 @@ void setup() {
4557
}
4658

4759
void loop() {
48-
4960
Log.raw("\r\n");
5061
Log.info("Going to sleep...");
5162
delay(100);
5263
WakeUpReason wakeup_reason = LowPower.sleep();
53-
Log.infof("Got out of sleep with wake up reason %d, doing work...\r\n",
54-
wakeup_reason);
5564

56-
delay(10000);
65+
switch (wakeup_reason) {
66+
case WakeUpReason::OK:
67+
Log.info("Finished sleep");
68+
break;
69+
case WakeUpReason::EXTERNAL_INTERRUPT:
70+
Log.info("Got woken up by external interrupt");
71+
break;
72+
case WakeUpReason::AWOKEN_BY_MODEM_PREMATURELY:
73+
Log.info("Got woken up by modem prematurely");
74+
break;
75+
case WakeUpReason::MODEM_TIMEOUT:
76+
Log.info(
77+
"Took too long to put modem in sleep, not time left for sleeping");
78+
break;
79+
case WakeUpReason::INVALID_SLEEP_TIME:
80+
Log.info("Got invalid sleep time from operator");
81+
break;
82+
}
83+
5784
// Do work ...
85+
Log.info("Doing work...");
86+
delay(5000);
5887
}

0 commit comments

Comments
 (0)