设置指定事件发生时将调用的事件处理程序(回调)函数。
用法
bleCharacteristic.setEventHandler(eventType, callback)
参数
- eventType:事件类型(BLESubscribed、BLEUnsubscribed、BLERead、BLEWritten)
- callback: 事件发生时调用的函数
返回
无
示例
// 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);
}
}
相关用法
- Arduino ArduinoBLE - bleCharacteristic.subscribe()用法及代码示例
- Arduino ArduinoBLE - bleCharacteristic.subscribed()用法及代码示例
- Arduino ArduinoBLE - bleCharacteristic.hasDescriptor()用法及代码示例
- Arduino ArduinoBLE - bleCharacteristic.uuid()用法及代码示例
- Arduino ArduinoBLE - bleCharacteristic.canRead()用法及代码示例
- Arduino ArduinoBLE - bleCharacteristic.addDescriptor()用法及代码示例
- Arduino ArduinoBLE - bleCharacteristic.broadcast()用法及代码示例
- Arduino ArduinoBLE - bleCharacteristic.properties()用法及代码示例
- Arduino ArduinoBLE - bleCharacteristic.written()用法及代码示例
- Arduino ArduinoBLE - bleCharacteristic.canSubscribe()用法及代码示例
- Arduino ArduinoBLE - bleCharacteristic.valueLength()用法及代码示例
- Arduino ArduinoBLE - bleCharacteristic.unsubscribe()用法及代码示例
- Arduino ArduinoBLE - bleCharacteristic.canUnsubscribe()用法及代码示例
- Arduino ArduinoBLE - bleCharacteristic.readValue()用法及代码示例
- Arduino ArduinoBLE - bleCharacteristic.value()用法及代码示例
- Arduino ArduinoBLE - bleCharacteristic.valueUpdated()用法及代码示例
- Arduino ArduinoBLE - bleCharacteristic.canWrite()用法及代码示例
- Arduino ArduinoBLE - bleCharacteristic.descriptor()用法及代码示例
- Arduino ArduinoBLE - bleCharacteristic.descriptorCount()用法及代码示例
- Arduino ArduinoBLE - bleCharacteristic.writeValue()用法及代码示例
- Arduino ArduinoBLE - bleCharacteristic.valueSize()用法及代码示例
- Arduino ArduinoBLE - bleDevice.advertisedServiceUuidCount()用法及代码示例
- Arduino ArduinoBLE - bleService.uuid()用法及代码示例
- Arduino ArduinoBLE - bleDescriptor.read()用法及代码示例
- Arduino ArduinoBLE - bleDevice.hasCharacteristic()用法及代码示例
注:本文由纯净天空筛选整理自arduino.cc大神的英文原创作品 ArduinoBLE - bleCharacteristic.setEventHandler()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。