write()
Description
This function writes data from a peripheral device in response to a request from a controller device, or queues bytes for transmission from a controller to peripheral device (in-between calls to
beginTransmission()
and endTransmission()
).Syntax
Wire.write(value)
Wire.write(string)
Wire.write(data, length)
Parameters
- value: a value to send as a single byte.
- string: a string to send as a series of bytes.
- data: an array of data to send as bytes.
- length: the number of bytes to transmit.
Returns
The number of bytes written (reading this number is optional).
Example
1#include <Wire.h>2
3byte val = 0;4
5void setup() { Wire.begin(); // Join I2C bus }6
7void loop() { Wire.beginTransmission(44); // Transmit to device number844 (0x2C)9
10 Wire.write(val); // Sends value byte11 Wire.endTransmission(); // Stop transmitting12
13 val++; // Increment value14
15 // if reached 64th position (max)16 if(val == 64) {17 val = 0; // Start over from lowest value18 }19
20 delay(500);21 }
Suggest changes
The content on docs.arduino.cc is facilitated through a public GitHub repository. If you see anything wrong, you can edit this page here.
License
The Arduino documentation is licensed under the Creative Commons Attribution-Share Alike 4.0 license.