// I2C Master // Push a button connected to the master controller // lights an LED connected to the slave // Andrew Sleigh // 2018-04-26 #include const int ledPin = 13; // the number of the LED pin int x = 0; void setup() { // initialize the LED pin as an output: pinMode(ledPin, OUTPUT); digitalWrite(ledPin, LOW); Wire.begin(7); // join i2c bus with address #7 // Attach a function to trigger when something is received. // From http://www.instructables.com/id/I2C-between-Arduinos/ Wire.onReceive(receiveEvent); } void receiveEvent(int bytes) { x = Wire.read(); // read one character from the I2C } void loop() { if (x == 0) { // received an OFF command digitalWrite(ledPin, LOW); } if (x == 1) { // received an ON command digitalWrite(ledPin, HIGH); } }