| 1 |
// Wire Slave Sender |
| 2 |
// by Nicholas Zambetti <http://www.zambetti.com> |
| 3 |
|
| 4 |
// Demonstrates use of the Wire library |
| 5 |
// Sends data as an I2C/TWI slave device |
| 6 |
// Refer to the "Wire Master Reader" example for use with this |
| 7 |
|
| 8 |
// Created 29 March 2006 |
| 9 |
|
| 10 |
// This example code is in the public domain. |
| 11 |
|
| 12 |
|
| 13 |
#include <Wire.h> |
| 14 |
|
| 15 |
void setup() { |
| 16 |
Wire.begin(8); // join I2C bus with address #8 |
| 17 |
Wire.onRequest(requestEvent); // register event |
| 18 |
} |
| 19 |
|
| 20 |
void loop() { |
| 21 |
delay(100); |
| 22 |
} |
| 23 |
|
| 24 |
// function that executes whenever data is requested by master |
| 25 |
// this function is registered as an event, see setup() |
| 26 |
void requestEvent() { |
| 27 |
Wire.write("hello "); // respond with message of 6 bytes |
| 28 |
// as expected by master |
| 29 |
} |