#include <Wire.h>
const int pinLed = PB4;
void setup() {
Wire.begin(9); // Address of slave 1
Wire.onReceive(receiveEvent);
pinMode(pinLed, OUTPUT);
}
void loop() {
// No code needed in the loop of a slave
}
void receiveEvent(int howMany) {
while (Wire.available()) {
char data = Wire.read();
// Controls the LED of slave 1
if (data == '0') {
digitalWrite(pinLed, HIGH);
} else {
digitalWrite(pinLed, LOW);
}
}
}