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.
