MicroBit.hのお話

これは、Mbed Advent Calendar 2017の11日目の記事です。

micro:bitに搭載されている、LEDマトリクスや各種センサーをMbedのオンラインコンパイラで手軽に使うために、micro:bit Device Abstraction Layer(microbit-dal)が提供されています。microbit-dalというとよくわからないですが、micro:bitのサンプルプログラムの最初にincludeするMicroBit.hのことです。

microbit-dalのAPI ドキュメントも用意されているので、サンプルコードと一緒に眺めれば、使い方は理解できるでしょう。 lancaster-university.github.io

 

microbit-dalを利用するためには、オンラインコンパイラの新規プロジェクト作成時に[An example of how to us he micro:bit DAL's abstraction]のtemplateを選択します。 そうすると、microbit-dalであるMicroBit.hがincludeされたプロジェクトが作成されます。

f:id:asagin:20171225220810p:plain
An example of how to us he micro:bit DAL's abstractionを選択

#include "MicroBit.h"

MicroBit uBit;

int main()
{
    // Initialise the micro:bit runtime.
    uBit.init();

    // Insert your code here!
    uBit.display.scrollAsync("abc123");
    //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();
}

明日は@toyowataさんです。