This is a very simple guide, reviewing the steps required to get Blinky working on an Mbed OS platform.

Mbed OS Blinky

This example shows the use of a DigitalOut object to represent an LED and use of the nonblocking Thread::wait() call. Using nonblocking calls is good practice because Mbed OS can schedule and run other threads while the first thread is waiting.

Building this example

Building with Arm Mbed CLI

To use Mbed CLI to build this example, follow the instructions in the documentation. The instructions here relate to using the Arm Online Compiler.

To use the Online Compiler, import this code into the Online Compiler, and select your platform from the top right. Compile the code using the compile button, load it onto your board and press the reset button on the board. The code will run on the board, and you will see the LED blink.

You can find more instructions for using the Mbed Online Compiler in the documentation.

Committer:
mbed_official
Date:
Mon Oct 14 14:00:04 2019 +0100
Revision:
100:ec006d6f3cb6
Parent:
98:f2d7e14c84a1
Child:
102:6979ad8bc0bc
Call `thread_sleep_for` to sleep (#193)

This function allows the application to be built wit the bare metal
profile without requiring `rtos-api` to be added in the list of required libraries.
.
Commit copied from https://github.com/ARMmbed/mbed-os-example-blinky

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 82:abf1b1785bd7 1 /* mbed Microcontroller Library
mbed_official 82:abf1b1785bd7 2 * Copyright (c) 2018 ARM Limited
mbed_official 82:abf1b1785bd7 3 * SPDX-License-Identifier: Apache-2.0
mbed_official 82:abf1b1785bd7 4 */
mbed_official 82:abf1b1785bd7 5
Jonathan Austin 0:2757d7abb7d9 6 #include "mbed.h"
mbed_official 100:ec006d6f3cb6 7 #include "platform/mbed_thread.h"
mbed_official 82:abf1b1785bd7 8 #include "stats_report.h"
Jonathan Austin 0:2757d7abb7d9 9
Jonathan Austin 0:2757d7abb7d9 10 DigitalOut led1(LED1);
Jonathan Austin 0:2757d7abb7d9 11
mbed_official 88:bea4f2daa48c 12 #define SLEEP_TIME 500 // (msec)
mbed_official 88:bea4f2daa48c 13 #define PRINT_AFTER_N_LOOPS 20
mbed_official 88:bea4f2daa48c 14
Jonathan Austin 1:846c97078558 15 // main() runs in its own thread in the OS
mbed_official 82:abf1b1785bd7 16 int main()
mbed_official 82:abf1b1785bd7 17 {
mbed_official 88:bea4f2daa48c 18 SystemReport sys_state( SLEEP_TIME * PRINT_AFTER_N_LOOPS /* Loop delay time in ms */);
mbed_official 82:abf1b1785bd7 19
mbed_official 88:bea4f2daa48c 20 int count = 0;
Jonathan Austin 0:2757d7abb7d9 21 while (true) {
mbed_official 82:abf1b1785bd7 22 // Blink LED and wait 0.5 seconds
Jonathan Austin 0:2757d7abb7d9 23 led1 = !led1;
mbed_official 100:ec006d6f3cb6 24 thread_sleep_for(SLEEP_TIME);
mbed_official 82:abf1b1785bd7 25
mbed_official 88:bea4f2daa48c 26 if ((0 == count) || (PRINT_AFTER_N_LOOPS == count)) {
mbed_official 88:bea4f2daa48c 27 // Following the main thread wait, report on the current system status
mbed_official 88:bea4f2daa48c 28 sys_state.report_state();
mbed_official 88:bea4f2daa48c 29 count = 0;
mbed_official 88:bea4f2daa48c 30 }
mbed_official 88:bea4f2daa48c 31 ++count;
Jonathan Austin 0:2757d7abb7d9 32 }
Jonathan Austin 0:2757d7abb7d9 33 }