write()
描述
如果是从端呼叫 write(),表示传送资料到请求资料的主端,如果是主端呼叫 write(),表示传送资料到从端,主端呼叫 write(),应该要在 beginTransmission() 和 endTransmission() 之间。
语法
Wire.write(value)
Wire.write(string)
Wire.write(data, length)
Parameters
value:要传送的资料,大小为一个位元组
string:要传送的资料,型态为 string
data:一个含有要传的资料的阵列
length:要传送的资料阵列的大小
回传
byte:回传 write() 传送的资料的位元组数量
范例
#include <Wire.h>
byte val = 0;
void setup()
{
Wire.begin(); // 初始化 I2C
}
void loop()
{
Wire.beginTransmission(44); // 开始传送资料到位址 44(0x2C) 的从端
Wire.write(val); // 写入资料
Wire.endTransmission(); // 中止传送
val++;
if(val == 64)
{
val = 0;
}
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.
