master_writer.ino 646 B

12345678910111213141516171819202122232425262728293031
  1. // Wire Master Writer
  2. // by Nicholas Zambetti <http://www.zambetti.com>
  3. // Demonstrates use of the Wire library
  4. // Writes data to an I2C/TWI slave device
  5. // Refer to the "Wire Slave Receiver" example for use with this
  6. // Created 29 March 2006
  7. // This example code is in the public domain.
  8. #include <Wire.h>
  9. void setup()
  10. {
  11. Wire.begin(); // join i2c bus (address optional for master)
  12. }
  13. byte x = 0;
  14. void loop()
  15. {
  16. Wire.beginTransmission(4); // transmit to device #4
  17. Wire.write("x is "); // sends five bytes
  18. Wire.write(x); // sends one byte
  19. Wire.endTransmission(); // stop transmitting
  20. x++;
  21. delay(500);
  22. }