Reference.WireWrite History

Hide minor edits - Show changes to markup

March 14, 2012, at 06:20 PM by Scott Fitzgerald -
Changed lines 27-29 from:

byte
write() will return the number of bytes written, though reading that number is optional

to:

byte: write() will return the number of bytes written, though reading that number is optional

October 31, 2011, at 02:42 PM by Tom Igoe -
Changed line 31 from:

[@

to:
Changed lines 55-56 from:

@]

to:
October 30, 2011, at 08:26 PM by Scott Fitzgerald -
Changed lines 27-30 from:

byte write()
will return the number of bytes written, though reading that number is optional

to:

byte
write() will return the number of bytes written, though reading that number is optional

October 30, 2011, at 08:26 PM by Scott Fitzgerald -
Changed lines 27-28 from:

None

to:

byte write()
will return the number of bytes written, though reading that number is optional

Changed lines 61-62 from:
to:
October 28, 2011, at 11:01 PM by Scott Fitzgerald -
Added lines 1-59:

Wire

write()

Description

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()).

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

None

Example

#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);
}

See also

Share