当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Arduino ArduinoBLE - bleCharacteristic.written()用法及代码示例


查询特征值是否已被其他蓝牙®低功耗设备写入。

用法

bleCharacteristic.written()

参数

None

返回

  • true如果特征值已由另一个 Bluetooth® Low Energy 设备写入,
  • false否则

示例


// Bluetooth® Low Energy LED Switch Characteristic - custom 128-bit UUID, read and writable by central
BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);




 // listen for Bluetooth® Low Energy peripherals to connect:
  BLEDevice central = BLE.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());

    // while the central is still connected to peripheral:
    while (central.connected()) {
      // if the remote device wrote to the characteristic,
      // use the value to control the LED:
      if (switchCharacteristic.written()) {
        if (switchCharacteristic.value()) {   // any value other than 0
          Serial.println("LED on");
          digitalWrite(ledPin, HIGH);         // will turn the LED on
        } else {                              // a 0 value
          Serial.println(F("LED off"));
          digitalWrite(ledPin, LOW);          // will turn the LED off
        }
      }
    }

    // when the central disconnects, print it out:
    Serial.print(F("Disconnected from central: "));
    Serial.println(central.address());
  }




相关用法


注:本文由纯净天空筛选整理自arduino.cc大神的英文原创作品 ArduinoBLE - bleCharacteristic.written()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。