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.

slave_sender.ino 859B

3 years ago
12345678910111213141516171819202122232425262728293031323334353637
  1. // Wire Slave Sender
  2. // by Nicholas Zambetti <http://www.zambetti.com>
  3. // Demonstrates use of the Wire library
  4. // Sends data as an I2C/TWI slave device
  5. // Refer to the "Wire Master Reader" 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(8); // join i2c bus with address #8
  14. Wire.onRequest(requestEvent); // register event
  15. }
  16. void loop()
  17. {
  18. delay(100);
  19. }
  20. // function that executes whenever data is requested by master
  21. // this function is registered as an event, see setup()
  22. void requestEvent()
  23. {
  24. digitalWrite(led, HIGH); // briefly flash the LED
  25. Wire.write("hello "); // respond with message of 6 bytes
  26. // as expected by master
  27. digitalWrite(led, LOW);
  28. }