1818#include < ArduinoBLE.h>
1919
2020
21- #define PAIR_BUTTON 3 // button for pairing
21+ #define PAIR_BUTTON 3 // button for pairing
2222#define PAIR_LED 24 // LED used to signal pairing
2323#define PAIR_LED_ON LOW // Blue LED on Nano BLE has inverted logic
24+ #define PAIR_LED_OFF HIGH // ... so these are inverted as well
2425#define PAIR_INTERVAL 30000 // interval for pairing after button press in ms
2526
2627#define CTRL_LED LED_BUILTIN
@@ -65,7 +66,7 @@ void setup() {
6566 });
6667
6768 // Callback to allow accepting or rejecting pairing
68- BLE.setBinaryConfirmPairing ([&acceptOrReject ](){
69+ BLE.setBinaryConfirmPairing ([](){
6970 Serial.print (" Should we confirm pairing? " );
7071 delay (5000 );
7172 if (acceptOrReject){
@@ -218,9 +219,10 @@ void loop() {
218219 BLE.setPairable (false );
219220 Serial.println (" No longer accepting pairing" );
220221 }
221- // Make LED blink while pairing is allowed
222- digitalWrite (PAIR_LED, (BLE.pairable () ? (millis ()%400 )<200 : BLE.paired ()) ? PAIR_LED_ON : !PAIR_LED_ON);
223222
223+ // Make LED blink while pairing is allowed, steady ON when paired
224+ bool led_status = BLE.pairable () ? (millis ()%400 )<200 : BLE.paired ();
225+ digitalWrite (PAIR_LED, led_status ? PAIR_LED_ON : PAIR_LED_OFF);
224226
225227 // if a central is connected to the peripheral:
226228 if (central && central.connected ()) {
@@ -261,4 +263,4 @@ void updateBatteryLevel() {
261263 batteryLevelChar.writeValue (batteryLevel); // and update the battery level characteristic
262264 oldBatteryLevel = batteryLevel; // save the level for next comparison
263265 }
264- }
266+ }
0 commit comments