// 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 buttonPin = 2; // the number of the pushbutton pin int buttonState = 1; // variable for reading the pushbutton status void setup() { Wire.begin(); // join i2c bus (address optional for master) Serial.begin(9600); // start serial for output // initialize the pushbutton pin as an input: pinMode(buttonPin, INPUT); } void loop() { // read the state of the pushbutton value: buttonState = digitalRead(buttonPin); // Serial.println(buttonState); // check if the pushbutton is pressed. if (buttonState == 1) { // turn LED on: Wire.beginTransmission(7); // address of slave is 7 Wire.write(1); // sends value byte Wire.endTransmission(); // stop transmitting } else { // turn LED off: Wire.beginTransmission(7); // address of slave is 7 Wire.write(0); // sends value byte Wire.endTransmission(); // stop transmitting } }