當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Arduino ArduinoBLE - bleCharacteristic.readValue()用法及代碼示例

讀取特性的當前值。如果特征在遠程設備上,將發送讀取請求。

用法

bleCharacteristic.readValue(buffer, length)
bleCharacteristic.readValue(value)

參數

  • buffer:將值讀入長度的字節數組:緩衝區參數的大小(以字節為單位)
  • value: 將值讀入的變量(通過引用)

返回

  • Number of bytes

示例


  while (peripheral.connected()) {
    // while the peripheral is connected

    // check if the value of the simple key characteristic has been updated
    if (simpleKeyCharacteristic.valueUpdated()) {
      // yes, get the value, characteristic is 1 byte so use byte value
      byte value = 0;

      simpleKeyCharacteristic.readValue(value);

      if (value & 0x01) {
        // first bit corresponds to the right button
        Serial.println("Right button pressed");
      }

      if (value & 0x02) {
        // second bit corresponds to the left button
        Serial.println("Left button pressed");
      }
    }
  }


相關用法


注:本文由純淨天空篩選整理自arduino.cc大神的英文原創作品 ArduinoBLE - bleCharacteristic.readValue()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。