read()
描述
读取藉由 I2C 介面传送过来的资料。如果是主端应该在呼叫 requestFrom()
后才呼叫 read()
。
read()
是从 Stream
继承而来。
语法
Wire.read()
参数
无参数
回传
byte
:从伺服器传送来的资料,如果没有资料可以读取,会回传 -1
范例
#include <Wire.h> void setup() { Wire.begin(); // 初始化 I2C Serial.begin(9600); // 初始化序列埠 } void loop() { Wire.requestFrom(2, 6); // 向 I2C 位址为 2 的从端请求六个位元组的资料 while(Wire.available()) { char c = Wire.read(); // 读取从端传送的资料 Serial.print(c); // 透过序列埠印出读取到的资料 } delay(500); }
The text of the 86Duino reference is a modification of the Arduino reference, and is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.