PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
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.

master_writer.ino 777B

123456789101112131415161718192021222324252627282930313233343536
  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. }