C/C++ code - bitty blue

micro:bit code

The following code will produce a hex file that can be used with Bitty Blue when compiled with Yotta or mbed. If you don't know how to do this, check the other Yotta tutorials for more information or simply load one of the prebuilt hexc files from the downloads page

Source Code

    #include "MicroBit.h"
    MicroBit uBit;
    void onConnected(MicroBitEvent)
    void onDisconnected(MicroBitEvent)
    int main()
        // Initialise the micro:bit runtime.
        uBit.messageBus.listen(MICROBIT_ID_BLE, MICROBIT_BLE_EVT_CONNECTED, onConnected);
        uBit.messageBus.listen(MICROBIT_ID_BLE, MICROBIT_BLE_EVT_DISCONNECTED, onDisconnected);
        new MicroBitAccelerometerService(*uBit.ble, uBit.accelerometer);
        new MicroBitButtonService(*uBit.ble);
        new MicroBitIOPinService(*uBit.ble, uBit.io);
        new MicroBitLEDService(*uBit.ble, uBit.display);
        new MicroBitMagnetometerService(*uBit.ble, uBit.compass);
        // 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.