write()
Wire.write()
Writes binary data to the serial port. This data is sent as a byte or series of bytes; to send the characters representing the digits of a number use the Print() function instead.
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() and endTransmission()).
Wire.write(value)
Wire.write(string)
Wire.write(data, length)
value
a value to send as a single byte
string
a value to send as a series of bytes
data
an array to send as bytes
length
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);
}