// The library for I2C communication
#include <Wire.h>
// Slave address
#define SLAVE_ADDRESS 0x55
// Button pin
#define BUTTON_PIN 8
void setup() {
// Initializing the communication
Wire.begin();
// Initializing the serial port
Serial.begin(115200);
// Initializing the button as INPUT
pinMode(BUTTON_PIN, INPUT);
}
void loop() {
// It checks the last state of the button
static bool lastButtonState = HIGH;
// It reads if the button is high or low
bool buttonState = digitalRead(BUTTON_PIN);
// If button is Low(PUSH) and the last state of the button
if (buttonState == LOW && lastButtonState == HIGH) {
// Initializes the communication with the slave
Wire.beginTransmission(SLAVE_ADDRESS);
// It sends a '1' to the slave
Wire.write('1');
// Ends the communication
Wire.endTransmission();
// Delay for the button debounce
delay(100);
}
// It updates the state of the button
lastButtonState = buttonState;
}