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


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

寫出特征值。如果特征在遠程設備上,將發送寫入請求或命令。

用法

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

參數

  • buffer: 要寫入值的字節數組
  • length: 要寫入的緩衝區參數的字節數
  • value: 要寫入的值

返回

  • 1關於成功,
  • 0失敗

示例


    // read the button pin
    int buttonState = digitalRead(buttonPin);

    if (oldButtonState != buttonState) {
      // button changed
      oldButtonState = buttonState;

      if (buttonState) {
        Serial.println("button pressed");

        // button is pressed, write 0x01 to turn the LED on
        ledCharacteristic.writeValue((byte)0x01);
      } else {
        Serial.println("button released");

        // button is released, write 0x00 to turn the LED off
        ledCharacteristic.writeValue((byte)0x00);
      }
    }


相關用法


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