should work with the data logger app to measure temperature, etc.

Dependencies:   microbit

Committer:
kinga
Date:
Thu Jan 19 10:14:02 2017 +0000
Revision:
0:9ac8338343fb
data_logger version 2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kinga 0:9ac8338343fb 1 /* See
kinga 0:9ac8338343fb 2 * http://lancaster-university.github.io/microbit-docs/advanced/
kinga 0:9ac8338343fb 3 * for docs about using the micro:bit library
kinga 0:9ac8338343fb 4 */
kinga 0:9ac8338343fb 5 #include "MicroBit.h"
kinga 0:9ac8338343fb 6
kinga 0:9ac8338343fb 7 MicroBit uBit;
kinga 0:9ac8338343fb 8
kinga 0:9ac8338343fb 9 void onConnected(MicroBitEvent)
kinga 0:9ac8338343fb 10 {
kinga 0:9ac8338343fb 11 uBit.display.print("C");
kinga 0:9ac8338343fb 12 }
kinga 0:9ac8338343fb 13
kinga 0:9ac8338343fb 14 void onDisconnected(MicroBitEvent)
kinga 0:9ac8338343fb 15 {
kinga 0:9ac8338343fb 16 uBit.display.print("D");
kinga 0:9ac8338343fb 17 }
kinga 0:9ac8338343fb 18
kinga 0:9ac8338343fb 19 int main()
kinga 0:9ac8338343fb 20 {
kinga 0:9ac8338343fb 21 // Initialise the micro:bit runtime.
kinga 0:9ac8338343fb 22 uBit.init();
kinga 0:9ac8338343fb 23 // Display a start-up message
kinga 0:9ac8338343fb 24 uBit.display.scroll("GREEN FOX");
kinga 0:9ac8338343fb 25
kinga 0:9ac8338343fb 26 // Application code will go here and in functions outside of main()
kinga 0:9ac8338343fb 27
kinga 0:9ac8338343fb 28 uBit.messageBus.listen(MICROBIT_ID_BLE, MICROBIT_BLE_EVT_CONNECTED, onConnected);
kinga 0:9ac8338343fb 29 uBit.messageBus.listen(MICROBIT_ID_BLE, MICROBIT_BLE_EVT_DISCONNECTED, onDisconnected);
kinga 0:9ac8338343fb 30
kinga 0:9ac8338343fb 31 new MicroBitAccelerometerService(*uBit.ble, uBit.accelerometer);
kinga 0:9ac8338343fb 32 new MicroBitMagnetometerService(*uBit.ble, uBit.compass);
kinga 0:9ac8338343fb 33 new MicroBitTemperatureService(*uBit.ble, uBit.thermometer);
kinga 0:9ac8338343fb 34
kinga 0:9ac8338343fb 35 // end of application code in main()
kinga 0:9ac8338343fb 36
kinga 0:9ac8338343fb 37 // If main exits, there may still be other fibers running or registered event handlers etc.
kinga 0:9ac8338343fb 38 // Simply release this fiber, which will mean we enter the scheduler. Worse case, we then
kinga 0:9ac8338343fb 39 // sit in the idle task forever, in a power efficient sleep.
kinga 0:9ac8338343fb 40 release_fiber();
kinga 0:9ac8338343fb 41 }