Arduino 4 Slave
#include <Wire.h> int pu_button_red = 2; int pu_led_red = 7; int pu_relay_red = 10; int pd_button_white = 4; int pd_led_white = 8; int pd_relay_white = 12; void setup() { Serial.begin(9600); Wire.begin(0x4); // join i2c bus with address #4 Wire.onReceive(receiveEvent); // register event pinMode(pu_button_red, INPUT); pinMode(pu_led_red, OUTPUT); pinMode(pu_relay_red, OUTPUT); pinMode(pd_button_white, INPUT); pinMode(pd_led_white, OUTPUT); pinMode(pd_relay_white, OUTPUT); } void loop() { /* Pull up configuration */ int pu_button_red_State = digitalRead(pu_button_red); if ( pu_button_red_State == LOW) { digitalWrite(pu_led_red, HIGH); digitalWrite(pu_relay_red, HIGH); } else { digitalWrite(pu_led_red, LOW); digitalWrite(pu_relay_red, LOW); } /* Pull down configuration */ int pd_button_white_State = digitalRead(pd_button_white); if ( pd_button_white_State == HIGH) { digitalWrite(pd_led_white, HIGH); digitalWrite(pd_relay_white, HIGH); } else { digitalWrite(pd_led_white, LOW); digitalWrite(pd_relay_white, LOW); } } // function that executes whenever data is received from master // this function is registered as an event, see setup() void receiveEvent(int howMany) { }