用mbed(C++)开发microbi

micro:bit编程、教学、展示
STEM
回复
头像
shaoziyang
帖子: 3919
注册时间: 2019年 10月 21日 13:48

用mbed(C++)开发microbi

#1

帖子 shaoziyang »

用makecode和python开发microbit虽然方便,使用mbed开发microbit同样简单,运行效率更高。下面几个程序显示了用Mbed开发的方法:

首先需要注册一个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(":)");
}
控制LED

虽然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();
}

回复

  • 随机主题
    回复总数
    阅读次数
    最新文章