Creating a program

Getting started

  1. Getting Started
  2. Downloading a Program
  3. Creating a Program
  4. Communicating with your mbed

This content relates to a deprecated version of Mbed

Mbed 2 is now deprecated. For the latest version please see the Mbed OS documentation.

The mbed Compiler is an online application used to create your own programs for the mbed microcontroller. It translates program source code that you write in to a program binary that the Microcontroller can execute.

The following instructions demonstrate how to generate the Program Binary used in the Microcontroller Getting Started example.

Instructions

1. Open the mbed Compiler

Open the online compiler using the link in the site menu (top-right of the page). This will open the Compiler in a new tab or window, so you can move back and forth to continue to read these instructions.

2. Create a New Program

/media/uploads/mbedofficial/new-project.png

/media/uploads/mbedofficial/main2.png

/media/uploads/mbedofficial/compiler-output.png

To create a new program in your personal Program Workspace:

  • Right-click (Mac users, Command-Click) on "My Programs", and select "New Program..."
  • Enter the name of the new program (e.g. "test"), and click "OK"

Your new program folder will be created under "My Programs".

3. View the default program source code

Click on the "main.cpp" file in your new program to open it in the file editor window. This is the main source code file in your program, and by default contains a simple program already. The code should look like:

Import program

00001 #include "mbed.h"
00002 
00003 DigitalOut myled(LED1);
00004 
00005 int main() {
00006     while(1) {
00007         myled = 1;
00008         wait(0.2);
00009         myled = 0;
00010         wait(0.2);
00011     }
00012 }

The other item in the program folder is the "mbed" library - this provides all the useful functions to start up and control the mbed Microcontroller, such as the DigitalOut interface used in this example.

4. Compile and Download the Program

To compile the program, click the Compile button in the toolbar. This will compile all the program source code files within the program folder to create a binary program.

  • After a successful compile, you will get a "Success!" message in the compiler output and the download dialog will pop up. Save it to the location of the mbed Microcontroller drive, and then hit reset on the microcontroller to start it running!
  • If there are errors, they will show up in the "Compiler Output" window, and will need to be fixed!

Where next

Troubleshooting

  • Some web browsers and download managers will automatically download files to a predefined location. To configure the download location so you can save it to the mbed Microcontroller, see Choose-where-to-save-files-FAQ
  • If you have problems using cut and paste functionality (Ctrl+C, Ctrl+V) in IE7, see Cut-and-paste-IE-FAQ

If you have any problems, or think this tutorial could be improved, please tell us in the Forum!


All wikipages