首先需要注册一个Mbed账号,就可以使用在线编译功能。
https://os.mbed.com/platforms/Microbit/
显示笑脸
代码: 全选
/* See
* http://lancaster-university.github.io/microbit-docs/advanced/
* for docs about using the micro:bit library
*/
#include "MicroBit.h"
MicroBitDisplay display;
int main()
{
while(1)
display.scroll(":)");
}
虽然microbit的LED是5x5点阵,但实际使用3x9方式控制的,一个LED需要两个GPIO。左上角(0,0)处LED使用P0.4和P0.13控制
代码: 全选
#include "mbed.h"
/*
* All the LEDs on the micro:bit are part of the LED Matrix,
* In order to get simple blinking behaviour, we set column 0
* to be permanently at ground. If you want to use the LEDs as
* a screen, there is a display driver in the micro:bit 'DAL',
*/
DigitalOut col0(P0_4, 0);
DigitalOut myled(P0_13);
int main() {
while(1) {
myled = 1;
wait(0.2);
myled = 0;
wait(0.2);
}
}
代码: 全选
#include "MicroBit.h"
MicroBit uBit;
int main()
{
// Initialise the micro:bit runtime.
uBit.init();
// Insert your code here!
uBit.display.scroll("HELLO WORLD! :)");
// If main exits, there may still be other fibers running or registered event handlers etc.
// Simply release this fiber, which will mean we enter the scheduler. Worse case, we then
// sit in the idle task forever, in a power efficient sleep.
release_fiber();
}