Micro:bit

Dependencies:   mbed microbit

Тесты по созданию связи между micro:bit и nRF51822 & BLE400 эта часть под micro:bit

Files at this revision

API Documentation at this revision

Comitter:
mamont090671
Date:
Fri Dec 13 08:21:42 2019 +0000
Parent:
6:98164ea9fa33
Commit message:
+1

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Thu Dec 12 08:35:54 2019 +0000
+++ b/main.cpp	Fri Dec 13 08:21:42 2019 +0000
@@ -29,14 +29,23 @@
     uint16_t applicationSpecificId;             /* An ID used to identify temperature value
                                                    in the manufacture specific AD data field */
     uint8_t tmpSensorValue; /* User defined application data */
+    uint8_t btnA_Value;
+    uint8_t btnB_Value;
 };
 #pragma pack()
 
+MicroBit ubit;
 BLE ble;
 //TMP_nrf51 tempSensor;
 DigitalOut alivenessLED(LED1, 1);
+
+DigitalIn buttonA(MICROBIT_PIN_BUTTON_A);
+DigitalIn buttonB(MICROBIT_PIN_BUTTON_B);
+
 static bool triggerTempValueUpdate = false;
 uint8_t temp;
+uint8_t bA;
+uint8_t bB;
 
 void periodicCallback(void)
 {
@@ -57,6 +66,8 @@
     appData.applicationSpecificId = APP_SPECIFIC_ID_TEST;
     /* Read a new temperature value */
     appData.tmpSensorValue = temp;
+    appData.btnA_Value = bA;
+    appData.btnB_Value = bB;
 }
 
 void temperatureValueAdvertising(void)
@@ -101,7 +112,7 @@
 
     Ticker ticker;
     /* Enable trigger every 2 seconds */
-    ticker.attach(periodicCallback, 2);
+    ticker.attach(periodicCallback, 1);
 
     ble.init();
     /* Start temperature advertising */
@@ -113,6 +124,16 @@
             updateSensorValueInAdvPayload();
             triggerTempValueUpdate = false;
         }
+        if(buttonA == 0x00) {
+            bA = 0x00;
+        } else if(buttonA == 0x01) {
+            bA = 0x01;
+        }
+        if(buttonB == 0x00) {
+            bB = 0x00;
+        } else if(buttonB == 0x01) {
+            bB = 0x01;
+        }
         ble.waitForEvent();
     }
 }