slave_sender.ino 702 B

1234567891011121314151617181920212223242526272829303132
  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. void setup()
  10. {
  11. Wire.begin(2); // join i2c bus with address #2
  12. Wire.onRequest(requestEvent); // register event
  13. }
  14. void loop()
  15. {
  16. delay(100);
  17. }
  18. // function that executes whenever data is requested by master
  19. // this function is registered as an event, see setup()
  20. void requestEvent()
  21. {
  22. Wire.write("hello "); // respond with message of 6 bytes
  23. // as expected by master
  24. }