You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
777B

  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. int led = LED_BUILTIN;
  10. void setup()
  11. {
  12. pinMode(led, OUTPUT);
  13. Wire.begin(); // join i2c bus (address optional for master)
  14. }
  15. byte x = 0;
  16. void loop()
  17. {
  18. digitalWrite(led, HIGH); // briefly flash the LED
  19. Wire.beginTransmission(9); // transmit to device #9
  20. Wire.write("x is "); // sends five bytes
  21. Wire.write(x); // sends one byte
  22. Wire.endTransmission(); // stop transmitting
  23. digitalWrite(led, LOW);
  24. x++;
  25. delay(500);
  26. }