onRequest() registers a callback function to be called when a controller device requests data from a peripheral device.
This function is part of the Wire library. See the Wire main page for more information.
Wire.onRequest(handler)
handler: the callback function to be called when data is requested. It should have the following signature:void (nothing).Nothing.
void setup() {
Wire.begin(0x08); // Join I2C bus as peripheral with address 0x08
Wire.onRequest(requestEvent); // Register callback function
}
void requestEvent() {
Wire.write("Hello"); // Send data to controller
}