void loop() { // listen for BLE peripherals to connect: BLECentral central = blePeripheral.central(); // if a central is connected to peripheral: if (central) { Serial.print("Connected to central: "); // print the central's MAC address: Serial.println(central.address()); // turn on the LED to indicate the connection: digitalWrite(13, HIGH); // check the heart rate measurement every 200ms // as long as the central is still connected: while (central.connected()) { long currentMillis = millis(); // if 200ms have passed, check the heart rate measurement: if (currentMillis - previousMillis >= 200) { previousMillis = currentMillis; updateHeartRate(); } } // when the central disconnects, turn off the LED: digitalWrite(13, LOW); Serial.print("Disconnected from central: "); Serial.println(central.address()); } }
void bleNotificationUnsubscribeHandler(BLECentral& central, BLECharacteristic& characteristic) { // value characteristic unsubscribe event handler DEBUG_PRINT("Unsubscribe event, central: "); DEBUG_PRINTLN(central.address()); }
void blePeripheralDisconnectHandler(BLECentral& central) { // central disconnected event handler DEBUG_PRINT("Disconnected event, central: "); DEBUG_PRINTLN(central.address()); }