![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
micro:bit мигалка
Dependencies: mbed BLE_API nRF51822
Программа для исполнительного устройства на micro:bit (nRF51822), включение\выключение светодиода по команде с управляющего устройства на nRF51822.
Diff: main.cpp
- Revision:
- 1:222379aed289
- Parent:
- 0:8ae63d3cc188
- Child:
- 2:ffd28faae17e
--- a/main.cpp Tue Aug 08 20:38:27 2017 +0000 +++ b/main.cpp Tue Oct 24 18:24:18 2017 +0000 @@ -18,10 +18,8 @@ #include "ble/BLE.h" #include "LEDService.h" - - -DigitalOut alivenessLED(p15, 0); -DigitalOut actuatedLED(p16, 0); +DigitalOut alivenessLED(p16, 0); +DigitalOut actuatedLED(p6, 0); Serial pc(p5, p4); @@ -33,10 +31,14 @@ LEDService *ledServicePtr; Ticker ticker; +bool onConnection = false; void periodicCallback(void) { - alivenessLED = !alivenessLED; /* Do blinky on LED1 to indicate system aliveness. */ + if(!onConnection){ + alivenessLED = !alivenessLED; /* Do blinky on LED1 to indicate system aliveness. */ + actuatedLED = 1; + } } /** @@ -49,12 +51,15 @@ { if ((params->handle == ledServicePtr->getValueHandle())) { actuatedLED = *(params->data); + onConnection = true; + alivenessLED = 1; } } void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params) { BLE::Instance().gap().startAdvertising(); + onConnection = false; } @@ -73,7 +78,7 @@ { BLE& ble = params->ble; ble_error_t error = params->error; - + if (error != BLE_ERROR_NONE) { /* In case of error, forward the error handling to onBleInitError */ onBleInitError(ble, error); @@ -106,18 +111,17 @@ pc.baud(115200); pc.printf("Initialization starts... \n"); ticker.attach(periodicCallback, ts); /* Blink LED every second */ + actuatedLED = 1; BLE &ble = BLE::Instance(); ble.init(bleInitComplete); /* SpinWait for initialization to complete. This is necessary because the * BLE object is used in the main loop below. */ - while (ble.hasInitialized() == false) { /* spin loop */ } + //while (ble.hasInitialized() == false) { /* spin loop */ } pc.printf("Initialization finished \n"); while (true) { - ble.waitForEvent(); - } }