Skip to content

Commit

Permalink
Add an EventQueue-based blinky to explain flow control (ARMmbed#115)
Browse files Browse the repository at this point in the history
To be used in mbed-os-5-docs/docs/api/io/flow_control.md
  • Loading branch information
LDong-Arm authored May 27, 2020
1 parent aea6616 commit 7ef375f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Tutorials_UsingAPIs/Flow-Control-EventQueue/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Application Flow Control: EventQueue example

An EventQueue Blinky implementation.
27 changes: 27 additions & 0 deletions Tutorials_UsingAPIs/Flow-Control-EventQueue/main.cpp
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();
}

0 comments on commit 7ef375f

Please sign in to comment.