Skip to content

Commit e370241

Browse files
author
Qinghao Shi
authored
Merge pull request #74 from maciejbocianski/move_sleep_examples
add Sleep examples
2 parents dc42ae9 + 9779fd8 commit e370241

File tree

4 files changed

+57
-0
lines changed

4 files changed

+57
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# DeepSleepLock example
2+
3+
Example use of the DeepSleepLock class.
4+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright (c) 2020 Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
#include "mbed.h"
6+
7+
InterruptIn button(BUTTON1);
8+
DigitalOut led(LED1);
9+
10+
void toggle()
11+
{
12+
led = !led;
13+
}
14+
15+
int main()
16+
{
17+
button.rise(&toggle);
18+
button.fall(&toggle);
19+
20+
// Lock deep sleep to decrease interrupt latency
21+
// at the expense of high power consumption
22+
DeepSleepLock lock;
23+
24+
while (1) {
25+
// Wait and let interrupts take care of the rest
26+
ThisThread::sleep_for(1000);
27+
}
28+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Sleep manager example
2+
3+
Example use of the sleep manager API.
4+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright (c) 2020 Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
#include "mbed.h"
6+
7+
8+
int main()
9+
{
10+
// Deep sleep for 1 second
11+
printf("Deep sleep allowed: %i\r\n", sleep_manager_can_deep_sleep());
12+
ThisThread::sleep_for(1000);
13+
14+
// Lock deep sleep
15+
printf("Locking deep sleep\r\n");
16+
sleep_manager_lock_deep_sleep();
17+
18+
// Sleep for 1 second
19+
printf("Deep sleep allowed: %i\r\n", sleep_manager_can_deep_sleep());
20+
ThisThread::sleep_for(1000);
21+
}

0 commit comments

Comments
 (0)