fork to bluetooth account
Fork of BTW_Eddystone_Solution1 by
main.cpp@10:a4ed1639d368, 2017-08-08 (annotated)
- Committer:
- bluetooth_kyo
- Date:
- Tue Aug 08 22:54:16 2017 +0000
- Revision:
- 10:a4ed1639d368
- Parent:
- 9:689c2e9e0439
change solution web site to plain bluetooth.com
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bluetooth_mdw | 0:580a61fd96a1 | 1 | #include "MicroBit.h" |
bluetooth_mdw | 0:580a61fd96a1 | 2 | |
bluetooth_mdw | 0:580a61fd96a1 | 3 | MicroBit uBit; |
bluetooth_mdw | 0:580a61fd96a1 | 4 | |
bluetooth_kyo | 10:a4ed1639d368 | 5 | char URL[] = "https://www.bluetooth.com"; |
wwbluetooth | 2:511941b33870 | 6 | |
wwbluetooth | 2:511941b33870 | 7 | // lvl : Pwr@ 1m : Pwr@ 0m |
wwbluetooth | 2:511941b33870 | 8 | // 0 : -90 : -49 |
wwbluetooth | 2:511941b33870 | 9 | // 1 : -78 : -37 |
wwbluetooth | 2:511941b33870 | 10 | // 2 : -74 : -33 |
wwbluetooth | 2:511941b33870 | 11 | // 3 : -69 : -28 |
wwbluetooth | 2:511941b33870 | 12 | // 4 : -66 : -25 |
wwbluetooth | 2:511941b33870 | 13 | // 5 : -61 : -20 |
wwbluetooth | 2:511941b33870 | 14 | // 6 : -56 : -15 |
bluetooth_kyo | 9:689c2e9e0439 | 15 | // 7 : -51 : -10 |
wwbluetooth | 2:511941b33870 | 16 | |
bluetooth_mdw | 0:580a61fd96a1 | 17 | const int8_t CALIBRATED_POWERS[] = {-49, -37, -33, -28, -25, -20, -15, -10}; |
bluetooth_mdw | 0:580a61fd96a1 | 18 | |
bluetooth_mdw | 0:580a61fd96a1 | 19 | uint8_t advertising = 0; |
bluetooth_mdw | 0:580a61fd96a1 | 20 | uint8_t tx_power_level = 6; |
bluetooth_mdw | 0:580a61fd96a1 | 21 | |
bluetooth_mdw | 0:580a61fd96a1 | 22 | void startAdvertising() { |
bluetooth_mdw | 0:580a61fd96a1 | 23 | uBit.bleManager.advertiseEddystoneUrl(URL, CALIBRATED_POWERS[tx_power_level-1], false); |
bluetooth_mdw | 0:580a61fd96a1 | 24 | uBit.bleManager.setTransmitPower(tx_power_level); |
bluetooth_mdw | 0:580a61fd96a1 | 25 | uBit.display.scroll("ADV"); |
bluetooth_mdw | 0:580a61fd96a1 | 26 | advertising = 1; |
bluetooth_mdw | 0:580a61fd96a1 | 27 | } |
bluetooth_mdw | 0:580a61fd96a1 | 28 | |
bluetooth_mdw | 0:580a61fd96a1 | 29 | void stopAdvertising() { |
bluetooth_mdw | 0:580a61fd96a1 | 30 | uBit.bleManager.stopAdvertising(); |
bluetooth_mdw | 0:580a61fd96a1 | 31 | uBit.display.scroll("OFF"); |
bluetooth_mdw | 0:580a61fd96a1 | 32 | advertising = 0; |
bluetooth_mdw | 0:580a61fd96a1 | 33 | } |
bluetooth_mdw | 0:580a61fd96a1 | 34 | |
bluetooth_mdw | 0:580a61fd96a1 | 35 | void onButtonA(MicroBitEvent) |
bluetooth_mdw | 0:580a61fd96a1 | 36 | { |
bluetooth_mdw | 0:580a61fd96a1 | 37 | if (advertising == 1) { |
bluetooth_mdw | 0:580a61fd96a1 | 38 | return; |
bluetooth_mdw | 0:580a61fd96a1 | 39 | } |
bluetooth_mdw | 0:580a61fd96a1 | 40 | startAdvertising(); |
bluetooth_mdw | 0:580a61fd96a1 | 41 | } |
bluetooth_mdw | 0:580a61fd96a1 | 42 | |
bluetooth_mdw | 0:580a61fd96a1 | 43 | void onButtonB(MicroBitEvent) |
bluetooth_mdw | 0:580a61fd96a1 | 44 | { |
bluetooth_mdw | 0:580a61fd96a1 | 45 | if (advertising == 0) { |
bluetooth_mdw | 0:580a61fd96a1 | 46 | return; |
bluetooth_mdw | 0:580a61fd96a1 | 47 | } |
bluetooth_mdw | 0:580a61fd96a1 | 48 | stopAdvertising(); |
bluetooth_mdw | 0:580a61fd96a1 | 49 | } |
bluetooth_mdw | 0:580a61fd96a1 | 50 | |
bluetooth_kyo | 9:689c2e9e0439 | 51 | |
bluetooth_kyo | 9:689c2e9e0439 | 52 | |
bluetooth_mdw | 0:580a61fd96a1 | 53 | int main() |
bluetooth_mdw | 0:580a61fd96a1 | 54 | { |
bluetooth_kyo | 9:689c2e9e0439 | 55 | // Initialize the micro:bit runtime. |
bluetooth_mdw | 0:580a61fd96a1 | 56 | uBit.init(); |
bluetooth_mdw | 0:580a61fd96a1 | 57 | |
bluetooth_mdw | 0:580a61fd96a1 | 58 | uBit.messageBus.listen(MICROBIT_ID_BUTTON_A, MICROBIT_BUTTON_EVT_CLICK, onButtonA); |
bluetooth_mdw | 0:580a61fd96a1 | 59 | uBit.messageBus.listen(MICROBIT_ID_BUTTON_B, MICROBIT_BUTTON_EVT_CLICK, onButtonB); |
bluetooth_mdw | 0:580a61fd96a1 | 60 | |
bluetooth_kyo | 9:689c2e9e0439 | 61 | uBit.bleManager.advertise(); //First Advertisment, adv name only |
bluetooth_mdw | 0:580a61fd96a1 | 62 | |
bluetooth_mdw | 0:580a61fd96a1 | 63 | release_fiber(); |
bluetooth_mdw | 0:580a61fd96a1 | 64 | } |