The example program for mbed pin-compatible platforms

Dependencies:   mbed

Deprecated

This is a blinky example for mbed 2. Please see the mbed OS 5 example.

Intro

This example demonstrates how to blink an led using the DigitalOut API. On all mbed platforms the pins LED1, LED2, LED3, and LED4 have mappings to led's on the board. Sometimes there are 4 different LED's, sometimes they all map to the same LED, sometimes they will map to pins on a tricolor led. This varies depending on who made the board, but the definitions are always valid.

How to use

Import this code into your compiler, select your platform from the top right, compile the code, load it onto your board, press the reset button on the board and you code will run. See the led blink!

Challenge

Challenge 1

Now, try changing which led's blink by changing LED1 to LED2-4. Check the pin mapping on your boards platform page for where the led's are mapped to.

Challenge 2

Try changing the speed the led's blink at by changing the numbers in the wait() function. The wait function is in seconds, so wait(0.5) waits for half a second.

Challenge 3

Try turning on multiple LED's at the same time. If you have a tri-color LED on the board this will make it change colors. If you have multiple LED's on the board you will be able to see multiple turn on. If you only have 1 LED on the board then this will do nothing special.

Files at this revision

API Documentation at this revision

Comitter:
mbed_official
Date:
Tue Feb 14 16:04:39 2017 +0000
Commit message:
A simple blinky example.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 3451e643c64c main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Feb 14 16:04:39 2017 +0000
@@ -0,0 +1,12 @@
+#include "mbed.h"
+
+DigitalOut myled(LED1);
+
+int main() {
+    while(1) {
+        myled = 1;
+        wait(0.2);
+        myled = 0;
+        wait(0.2);
+    }
+}
diff -r 000000000000 -r 3451e643c64c mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Feb 14 16:04:39 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/176b8275d35d
\ No newline at end of file