KEN OGAMI / microbit-accelerometer-led

Dependencies:   microbit-acc

Fork of microbit-animator-starter by Martin Woolley

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /*
00002 The MIT License (MIT)
00003 
00004 Copyright (c) 2016 British Broadcasting Corporation.
00005 This software is provided by Lancaster University by arrangement with the BBC.
00006 
00007 Permission is hereby granted, free of charge, to any person obtaining a
00008 copy of this software and associated documentation files (the "Software"),
00009 to deal in the Software without restriction, including without limitation
00010 the rights to use, copy, modify, merge, publish, distribute, sublicense,
00011 and/or sell copies of the Software, and to permit persons to whom the
00012 Software is furnished to do so, subject to the following conditions:
00013 
00014 The above copyright notice and this permission notice shall be included in
00015 all copies or substantial portions of the Software.
00016 
00017 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00018 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00019 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO Animation SHALL
00020 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00021 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00022 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00023 DEALINGS IN THE SOFTWARE.
00024 */
00025 
00026 // 8th March 2017
00027 
00028 #include "MicroBit.h"
00029 #include "Animator.h"
00030 #include <math.h>
00031 
00032 MicroBit uBit;
00033 
00034 void onConnected(MicroBitEvent) 
00035 { 
00036     uBit.display.print("C"); 
00037 } 
00038  
00039 void onDisconnected(MicroBitEvent) 
00040 { 
00041     uBit.display.print("D"); 
00042 } 
00043  
00044 int main() 
00045 { 
00046     // Initialise the micro:bit runtime. 
00047     uBit.init(); 
00048  
00049     uBit.display.print("X"); 
00050  
00051     uBit.messageBus.listen(MICROBIT_ID_BLE, MICROBIT_BLE_EVT_CONNECTED, onConnected); 
00052     uBit.messageBus.listen(MICROBIT_ID_BLE, MICROBIT_BLE_EVT_DISCONNECTED, onDisconnected); 
00053  
00054     // services: note that the device information service is included by default 
00055     // see config.json property microbit-dal.bluetooth. device_info_service 
00056  
00057     new MicroBitAccelerometerService(*uBit.ble, uBit.accelerometer); 
00058     new MicroBitLEDService(*uBit.ble, uBit.display); 
00059     new MicroBitTemperatureService(*uBit.ble, uBit.thermometer);
00060  
00061     release_fiber(); 
00062 }