fork to bluetooth account.
Dependencies: microbit-iBeacon
Fork of BluetoothWorldBeaconsClass by
Beacon Hands-on-Training project used as starter for class.
Libraries updated to use microbit-iBeacon -> microbit-dal-iBeacon to support both Eddystone and iBeacon formats.
Diff: main.cpp
- Revision:
- 8:fe392760d077
- Parent:
- 7:e4f28f8f1325
- Child:
- 9:69427df8fe06
diff -r e4f28f8f1325 -r fe392760d077 main.cpp --- a/main.cpp Mon Oct 16 18:47:21 2017 +0000 +++ b/main.cpp Mon Oct 16 20:25:30 2017 +0000 @@ -2,64 +2,7 @@ MicroBit uBit; -char URL[] = "https://bluetooth.com"; - -// lvl : Pwr@ 1m : Pwr@ 0m -// 0 : -90 : -49 -// 1 : -78 : -37 -// 2 : -74 : -33 -// 3 : -69 : -28 -// 4 : -66 : -25 -// 5 : -61 : -20 -// 6 : -56 : -15 -// 7 : -51 : -10 - -const int8_t CALIBRATED_POWERS[] = {-49, -37, -33, -28, -25, -20, -15, -10}; - -uint8_t advertising = 0; -uint8_t tx_power_level = 6; - -void startAdvertising() { - uBit.bleManager.advertiseEddystoneUrl(URL, CALIBRATED_POWERS[tx_power_level-1], false); - uBit.bleManager.setTransmitPower(tx_power_level); - uBit.display.scroll("ADV"); - advertising = 1; -} - -void stopAdvertising() { - uBit.bleManager.stopAdvertising(); - uBit.display.scroll("OFF"); - advertising = 0; -} - -void onButtonA(MicroBitEvent) -{ - if (advertising == 1) { - return; - } - startAdvertising(); -} - -void onButtonB(MicroBitEvent) -{ - if (advertising == 0) { - return; - } - stopAdvertising(); -} - - int main() { - // Initialize the micro:bit runtime. - uBit.init(); - - uBit.messageBus.listen(MICROBIT_ID_BUTTON_A, MICROBIT_BUTTON_EVT_CLICK, onButtonA); - uBit.messageBus.listen(MICROBIT_ID_BUTTON_B, MICROBIT_BUTTON_EVT_CLICK, onButtonB); - - uBit.bleManager.advertise(); //First Advertisment, adv name only - - release_fiber(); - }