micro:bit and PiBorg i2c motor driver (PiBorg Reverse) example program for a Web Bluetooth demo that lets you drive around a 4WD buggy http://www.thebubbleworks.com/
Dependencies: BLE_API NanoBit PicoBorgReverse mbed nRF51822
Diff: main.cpp
- Revision:
- 1:5e5183fed184
- Parent:
- 0:9ea115d01a95
diff -r 9ea115d01a95 -r 5e5183fed184 main.cpp --- a/main.cpp Mon Mar 14 09:17:39 2016 +0000 +++ b/main.cpp Mon Mar 14 10:37:25 2016 +0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Wayne Keenan + * Copyright (c) 2016 https://www.thebubbleworks.com/ * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + + +// For more information, such as the Web Bluetooth remote controller, please see https://www.thebubbleworks.com/ +#define MY_DBG_ENABLED 1 + #include "MyDebug.h" #include "PicoBorgReverse.h" @@ -21,6 +26,7 @@ #include "ble/BLE.h" #include "ble/services/UARTService.h" +// Nano smaller than Micro, in this case, a cut down library... #include "NanoBitPins.h" #include "NanoBitDisplay.h" @@ -29,6 +35,23 @@ #ifdef MY_DBG_ENABLED Serial serial(MICROBIT_PIN_USBTX, MICROBIT_PIN_USBRX); + +// Use 5 of the micro:bit on-board LED's for status information + +#define TRACE_INIT() MicroBitDisplay display; display.clear(); +#define TRACE_START() display.setPixel(0,0); +#define TRACE_BLE_INIT() display.setPixel(0,1); +#define TRACE_BLE_STARTED() display.setPixel(0,2); +#define TRACE_MOTOR_STATUS(x) display.setPixel(0,3, x); +#define TRACE_BLE_CONNECTED(x) display.setPixel(0,4, x); +#else +// or don't. +#define TRACE_INIT() +#define TRACE_START() +#define TRACE_BLE_INIT() +#define TRACE_BLE_STARTED() +#define TRACE_MOTOR_STATUS(x) +#define TRACE_BLE_CONNECTED(x) #endif @@ -68,6 +91,8 @@ //---------------------------------------------------- +// Try to reduce transfer latency (optional, the central device may ignore this 'request') +// The opposite of low power :) https://developer.mbed.org/questions/54515/How-to-lower-power-consumption/ void connectionCallback(const Gap::ConnectionCallbackParams_t *params) { @@ -128,15 +153,8 @@ triggerSensorPolling = true; } - - -// The opposite of low power :) https://developer.mbed.org/questions/54515/How-to-lower-power-consumption/ - - - - - //---------------------------------------------------- +// PiBorg Reverese motor controller functions void motorReset() { pbr->resetEpo(); @@ -178,12 +196,6 @@ //---------------------------------------------------- -#define TRACE_INIT() MicroBitDisplay display; display.clear(); -#define TRACE_START() display.setPixel(0,0); -#define TRACE_BLE_INIT() display.setPixel(0,1); -#define TRACE_BLE_STARTED() display.setPixel(0,2); -#define TRACE_MOTOR_STATUS(x) display.setPixel(0,3, x); -#define TRACE_BLE_CONNECTED(x) display.setPixel(0,4, x); int main(void) { @@ -199,11 +211,11 @@ ble.init(bleInitComplete); TRACE_BLE_INIT(); while (ble.hasInitialized() == false) { /* spin loop */ } - TRACE_BLE_STARTED() + TRACE_BLE_STARTED(); // Setup Motors bool motorInitOK = motorInit(); - display.setPixel(0,3, motorInitOK); + TRACE_MOTOR_STATUS(motorInitOK); MY_DBG_PRINT("Go!\n");