Skip to content

Commit 7ef375f

Browse files
authored
Add an EventQueue-based blinky to explain flow control (#115)
To be used in mbed-os-5-docs/docs/api/io/flow_control.md
1 parent aea6616 commit 7ef375f

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Application Flow Control: EventQueue example
2+
3+
An EventQueue Blinky implementation.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (c) 2020 Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#include "mbed.h"
7+
8+
void flip(DigitalOut &led)
9+
{
10+
led = !led;
11+
}
12+
13+
int main()
14+
{
15+
DigitalOut led1(LED1);
16+
DigitalOut led2(LED2);
17+
18+
// creates a queue with the default size
19+
EventQueue queue;
20+
21+
// events are simple callbacks
22+
queue.call_every(1000, flip, led1);
23+
queue.call_every(500, flip, led2);
24+
25+
// events are executed by the dispatch method
26+
queue.dispatch_forever();
27+
}

0 commit comments

Comments
 (0)