Import guide for mbed compiler
This guide shows you how to import libraries into your projects in the mbed compiler.
Here is a direct link to the compiler where you write your mbed code.
Create a new project
In your compiler press the drop down arrow on the New
button in the top left part of the compiler and select New program
.
In the pop up you enter your platform and your project name. You can either use a pre defined template or have an empty project. We will choose no template here.
Right click your new project in the left column and select New file
.
Name your file main.cpp
.
Import a library to your project
In the left column of your compiler, locate your project.
Right click your project and select Import Library -> From Import Wizard ...
.
You are now shown the Import Wizard
, here you can find libraries on mbed.org and import these.
The first library in your list should be mbed
.
Double click this to import it.
If you need to search for libraries you can so do by using the search field in the top right area.
Using your imported library
Go back to your main.cpp
file.
You can now use your imported library in your other files.
To do this you need to include the library with this code snippet #include ...
.
The following code imports the mbed library and makes the first led blink.
#include "mbed.h"
DigitalOut myled(LED1);
int main() {
while(1) { // infinite loop
myled = 1;
wait(0.2);
myled = 0;
wait(0.2);
}
}
Now you can compile and run your code! Check our our compile guide for infor about how to do that.