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


Arduino read()用法及代碼示例

說明

此函數讀取在調用requestFrom() 後從外圍設備傳輸到控製器設備或從控製器設備傳輸到外圍設備的字節。 read() 繼承自 Stream 實用程序類。

用法

Wire.read()

參數

None。

返回

接收到的下一個字節。

示例

#include <Wire.h>

void setup() {
  Wire.begin();             // Join I2C bus (address is optional for controller device)
  Serial.begin(9600);       // Start serial for output
}

void loop() {
    Wire.requestFrom(2, 6);    // Request 6 bytes from slave device number two

    // Slave may send less than requested
    while(Wire.available()) {
        char c = Wire.read();    // Receive a byte as character
        Serial.print(c);         // Print the character
    }

    delay(500);
}

相關用法


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