Skip to content

add Sleep examples #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions APIs_Platform/DeepSleepLock_Example_1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# DeepSleepLock example

Example use of the DeepSleepLock class.

28 changes: 28 additions & 0 deletions APIs_Platform/DeepSleepLock_Example_1/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2020 Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*/
#include "mbed.h"

InterruptIn button(BUTTON1);
DigitalOut led(LED1);

void toggle()
{
led = !led;
}

int main()
{
button.rise(&toggle);
button.fall(&toggle);

// Lock deep sleep to decrease interrupt latency
// at the expense of high power consumption
DeepSleepLock lock;

while (1) {
// Wait and let interrupts take care of the rest
ThisThread::sleep_for(1000);
}
}
4 changes: 4 additions & 0 deletions APIs_Platform/SleepManager_Example_1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Sleep manager example

Example use of the sleep manager API.

21 changes: 21 additions & 0 deletions APIs_Platform/SleepManager_Example_1/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (c) 2020 Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*/
#include "mbed.h"


int main()
{
// Deep sleep for 1 second
printf("Deep sleep allowed: %i\r\n", sleep_manager_can_deep_sleep());
ThisThread::sleep_for(1000);

// Lock deep sleep
printf("Locking deep sleep\r\n");
sleep_manager_lock_deep_sleep();

// Sleep for 1 second
printf("Deep sleep allowed: %i\r\n", sleep_manager_can_deep_sleep());
ThisThread::sleep_for(1000);
}