Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of BluetoothWorldBeaconsClass by
Revision 7:a6a3137843c6, committed 2017-09-26
- Comitter:
- PEZAT
- Date:
- Tue Sep 26 07:34:31 2017 +0000
- Parent:
- 6:7343c9b85d7f
- Commit message:
- Update Code
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Aug 03 18:25:18 2017 +0000
+++ b/main.cpp Tue Sep 26 07:34:31 2017 +0000
@@ -2,12 +2,68 @@
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();
+//******************************************************************************************
}
