Reference Language | Libraries | Comparison | Changes
ArduinoBLE : BLECharacteristic class
setEventHandler()
Description
Set the event handler (callback) function that will be called when the specified event occurs.
Syntax
bleCharacteristic.setEventHandler(eventType, callback)
Parameters
eventType: event type (BLESubscribed, BLEUnsubscribed, BLERead, BLEWritten)
callback: function to call when the event occurs
Returns
Nothing
Example
…
// create switch characteristic and allow remote device to read and write
BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);
// …
// assign event handlers for characteristic
switchCharacteristic.setEventHandler(BLEWritten, switchCharacteristicWritten);
// …
void switchCharacteristicWritten(BLEDevice central, BLECharacteristic characteristic) {
// central wrote new value to characteristic, update LED
Serial.print("Characteristic event, written: ");
if (switchCharacteristic.value()) {
Serial.println("LED on");
digitalWrite(ledPin, HIGH);
} else {
Serial.println("LED off");
digitalWrite(ledPin, LOW);
}
}
…
See Also
Reference Home
Corrections, suggestions, and new documentation should be posted to the Forum.
The text of the Arduino reference is licensed under a
Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.