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.

Files at this revision

API Documentation at this revision

Comitter:
mbed_official
Date:
Tue Jan 08 12:45:03 2019 +0000
Parent:
87:4c31b7ef1391
Child:
89:448e37ce650a
Commit message:
Merge pull request #155 from deepikabhavnani/print_fix

Set the baudrate to default and reduce prints in blinky
.
Commit copied from https://github.com/ARMmbed/mbed-os-example-blinky

Changed in this revision

README.md Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed_app.json Show annotated file Show diff for this revision Revisions of this file
--- a/README.md	Mon Jan 07 12:00:02 2019 +0000
+++ b/README.md	Tue Jan 08 12:45:03 2019 +0000
@@ -110,9 +110,7 @@
 
 ### Output
 
-To view the serial output you can use any terminal client of your choosing such as [PuTTY](http://www.putty.org/) or [CoolTerm](http://freeware.the-meiers.org/).
-
-The default baud rate for this application is set to `115200` and may be modified in the `mbed_app.json` file.
+To view the serial output you can use any terminal client of your choosing such as [PuTTY](http://www.putty.org/) or [CoolTerm](http://freeware.the-meiers.org/). Unless otherwise specified, printf defaults to a baud rate of 9600 on Mbed OS.
 
 You can find more information on the Mbed OS configuration tools and serial communication in Mbed OS in the related [related links section](#related-links).
 
--- a/main.cpp	Mon Jan 07 12:00:02 2019 +0000
+++ b/main.cpp	Tue Jan 08 12:45:03 2019 +0000
@@ -8,17 +8,25 @@
 
 DigitalOut led1(LED1);
 
+#define SLEEP_TIME                  500 // (msec)
+#define PRINT_AFTER_N_LOOPS         20
+
 // main() runs in its own thread in the OS
 int main()
 {
-    SystemReport sys_state(500 /* Loop delay time in ms */);
+    SystemReport sys_state( SLEEP_TIME * PRINT_AFTER_N_LOOPS /* Loop delay time in ms */);
 
+    int count = 0;
     while (true) {
         // Blink LED and wait 0.5 seconds
         led1 = !led1;
-        wait_ms(500);
+        wait_ms(SLEEP_TIME);
 
-        // Following the main thread wait, report on the current system status
-        sys_state.report_state();
+        if ((0 == count) || (PRINT_AFTER_N_LOOPS == count)) {
+            // Following the main thread wait, report on the current system status
+            sys_state.report_state();
+            count = 0;
+        }
+        ++count;
     }
 }
--- a/mbed_app.json	Mon Jan 07 12:00:02 2019 +0000
+++ b/mbed_app.json	Tue Jan 08 12:45:03 2019 +0000
@@ -1,7 +1,6 @@
 {
     "target_overrides": {
         "*": {
-            "platform.stdio-baud-rate": 115200,
             "platform.stack-stats-enabled": true,
             "platform.heap-stats-enabled": true,
             "platform.cpu-stats-enabled": true,