onReceiveI2C()

[Inter Integrated Circuit]
void onReceiveI2C(void (*function)(int));

Description

Sets the function that will be called when the I2C bus receives data.

Parameters

function: the function that will be called when the I2C bus receives data.

Returns

Nothing.

Example Code

The code initializes the I2C communication with the SDA pin connected to pin 4, the SCL pin connected to pin 5, and the address of the chip set to 0x20.

Sets the function receiveEvent to be called when the I2C bus receives data.

void receiveEvent(int howMany) {
    // code to be executed when the I2C bus receives data
}

void setup() {
    beginI2C(4, 5, 0x20);  // initializes the I2C communication with the SDA pin connected to pin 4, the SCL pin connected to pin 5, and the address of the chip set to 0x20
    onReceiveI2C(receiveEvent);  // sets the function receiveEvent to be called when the I2C bus receives data
}

void loop() {
}

Notes and Warnings

The parameter function must be a function that receives an integer as a parameter.