forking app
Fork of microbit-animator-starter by
main.cpp@6:fc5be6e23702, 2017-11-29 (annotated)
- Committer:
- bluetooth_kyo
- Date:
- Wed Nov 29 22:44:10 2017 +0000
- Revision:
- 6:fc5be6e23702
- Parent:
- 5:ed00381f279a
forking app
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bluetooth_mdw | 0:b821de9e1c1f | 1 | /* |
bluetooth_mdw | 0:b821de9e1c1f | 2 | The MIT License (MIT) |
bluetooth_mdw | 0:b821de9e1c1f | 3 | |
bluetooth_mdw | 0:b821de9e1c1f | 4 | Copyright (c) 2016 British Broadcasting Corporation. |
bluetooth_mdw | 0:b821de9e1c1f | 5 | This software is provided by Lancaster University by arrangement with the BBC. |
bluetooth_mdw | 0:b821de9e1c1f | 6 | |
bluetooth_mdw | 0:b821de9e1c1f | 7 | Permission is hereby granted, free of charge, to any person obtaining a |
bluetooth_mdw | 0:b821de9e1c1f | 8 | copy of this software and associated documentation files (the "Software"), |
bluetooth_mdw | 0:b821de9e1c1f | 9 | to deal in the Software without restriction, including without limitation |
bluetooth_mdw | 0:b821de9e1c1f | 10 | the rights to use, copy, modify, merge, publish, distribute, sublicense, |
bluetooth_mdw | 0:b821de9e1c1f | 11 | and/or sell copies of the Software, and to permit persons to whom the |
bluetooth_mdw | 0:b821de9e1c1f | 12 | Software is furnished to do so, subject to the following conditions: |
bluetooth_mdw | 0:b821de9e1c1f | 13 | |
bluetooth_mdw | 0:b821de9e1c1f | 14 | The above copyright notice and this permission notice shall be included in |
bluetooth_mdw | 0:b821de9e1c1f | 15 | all copies or substantial portions of the Software. |
bluetooth_mdw | 0:b821de9e1c1f | 16 | |
bluetooth_mdw | 0:b821de9e1c1f | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
bluetooth_mdw | 0:b821de9e1c1f | 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
bluetooth_mdw | 0:b821de9e1c1f | 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO Animation SHALL |
bluetooth_mdw | 0:b821de9e1c1f | 20 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
bluetooth_mdw | 0:b821de9e1c1f | 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
bluetooth_mdw | 0:b821de9e1c1f | 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
bluetooth_mdw | 0:b821de9e1c1f | 23 | DEALINGS IN THE SOFTWARE. |
bluetooth_mdw | 0:b821de9e1c1f | 24 | */ |
bluetooth_mdw | 0:b821de9e1c1f | 25 | |
bluetooth_mdw | 2:ceab125d609b | 26 | // 8th March 2017 |
bluetooth_mdw | 2:ceab125d609b | 27 | |
bluetooth_mdw | 0:b821de9e1c1f | 28 | #include "MicroBit.h" |
bluetooth_mdw | 0:b821de9e1c1f | 29 | #include "Animator.h" |
bluetooth_mdw | 0:b821de9e1c1f | 30 | #include <math.h> |
bluetooth_mdw | 0:b821de9e1c1f | 31 | |
bluetooth_mdw | 0:b821de9e1c1f | 32 | MicroBit uBit; |
bluetooth_mdw | 0:b821de9e1c1f | 33 | |
bluetooth_kyo | 5:ed00381f279a | 34 | void onConnected(MicroBitEvent) |
bluetooth_kyo | 5:ed00381f279a | 35 | { |
bluetooth_kyo | 5:ed00381f279a | 36 | uBit.display.print("C"); |
bluetooth_kyo | 5:ed00381f279a | 37 | } |
bluetooth_kyo | 5:ed00381f279a | 38 | |
bluetooth_kyo | 5:ed00381f279a | 39 | void onDisconnected(MicroBitEvent) |
bluetooth_kyo | 5:ed00381f279a | 40 | { |
bluetooth_kyo | 5:ed00381f279a | 41 | uBit.display.print("D"); |
bluetooth_kyo | 5:ed00381f279a | 42 | } |
bluetooth_kyo | 5:ed00381f279a | 43 | |
bluetooth_kyo | 5:ed00381f279a | 44 | int main() |
bluetooth_kyo | 5:ed00381f279a | 45 | { |
bluetooth_kyo | 5:ed00381f279a | 46 | // Initialise the micro:bit runtime. |
bluetooth_kyo | 5:ed00381f279a | 47 | uBit.init(); |
bluetooth_kyo | 5:ed00381f279a | 48 | |
bluetooth_kyo | 5:ed00381f279a | 49 | uBit.display.print("X"); |
bluetooth_kyo | 5:ed00381f279a | 50 | |
bluetooth_kyo | 5:ed00381f279a | 51 | uBit.messageBus.listen(MICROBIT_ID_BLE, MICROBIT_BLE_EVT_CONNECTED, onConnected); |
bluetooth_kyo | 5:ed00381f279a | 52 | uBit.messageBus.listen(MICROBIT_ID_BLE, MICROBIT_BLE_EVT_DISCONNECTED, onDisconnected); |
bluetooth_kyo | 5:ed00381f279a | 53 | |
bluetooth_kyo | 5:ed00381f279a | 54 | // services: note that the device information service is included by default |
bluetooth_kyo | 5:ed00381f279a | 55 | // see config.json property microbit-dal.bluetooth. device_info_service |
bluetooth_kyo | 5:ed00381f279a | 56 | |
bluetooth_kyo | 5:ed00381f279a | 57 | new MicroBitAccelerometerService(*uBit.ble, uBit.accelerometer); |
bluetooth_kyo | 5:ed00381f279a | 58 | new MicroBitLEDService(*uBit.ble, uBit.display); |
bluetooth_kyo | 5:ed00381f279a | 59 | new MicroBitTemperatureService(*uBit.ble, uBit.thermometer); |
bluetooth_kyo | 5:ed00381f279a | 60 | |
bluetooth_kyo | 5:ed00381f279a | 61 | release_fiber(); |
bluetooth_mdw | 0:b821de9e1c1f | 62 | } |