[Wire]
描述
Writes data from a slave device in response to a request from a master, or queues bytes for transmission from a master to slave device.
(in-between calls to beginTransmission() 以及 endTransmission())
語法
Wire.write(value) Wire.write(string) Wire.write(data, length)
參數
value: a value to send as a single byte字串 (string): a string to send as a series of bytesdata: an array of data to send as byteslength: the number of bytes to transmit
回傳
byte: write() will return the number of bytes written, though reading that number is optional
範例
#include <Wire.h>
byte val = 0;
void setup()
{
Wire.begin(); // join i2c bus
}
void loop()
{
Wire.beginTransmission(44); // transmit to device #44 (0x2c)
// device address is specified in datasheet
Wire.write(val); // sends value byte
Wire.endTransmission(); // stop transmitting
val++; // increment value
if(val == 64) // if reached 64th position (max)
{
val = 0; // start over from lowest value
}
delay(500);
}函式庫參考主頁面
86Duino 參考的文本是根據 知識共享署名-相同方式分享 3.0 許可證,部分文本是從 Arduino 參考 修改的。 參考中的代碼示例已發佈到公共領域。