forked from ARMmbed/mbed-os-examples-docs_only
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an EventQueue-based blinky to explain flow control (ARMmbed#115)
To be used in mbed-os-5-docs/docs/api/io/flow_control.md
- Loading branch information
Showing
2 changed files
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Application Flow Control: EventQueue example | ||
|
||
An EventQueue Blinky implementation. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright (c) 2020 Arm Limited and affiliates. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include "mbed.h" | ||
|
||
void flip(DigitalOut &led) | ||
{ | ||
led = !led; | ||
} | ||
|
||
int main() | ||
{ | ||
DigitalOut led1(LED1); | ||
DigitalOut led2(LED2); | ||
|
||
// creates a queue with the default size | ||
EventQueue queue; | ||
|
||
// events are simple callbacks | ||
queue.call_every(1000, flip, led1); | ||
queue.call_every(500, flip, led2); | ||
|
||
// events are executed by the dispatch method | ||
queue.dispatch_forever(); | ||
} |