#include <Wire.h>
const int pushButton2 = D2;
const int pushButton3 = D3;
const int led1 = D0;
const int led2 = D1;
void setup() {
Wire.begin();
pinMode(pushButton2, INPUT);
pinMode(pushButton3, INPUT);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
Serial.begin(9600); // Start serial communication for debugging
}
void loop() {
int buttonState2 = digitalRead(pushButton2); // Read the state of button 2
int buttonState3 = digitalRead(pushButton3); // Read the state of button 3
if (buttonState2 == HIGH) {
// Increase 5 degrees on slave 1 and decrease 5 degrees on slave 2
Wire.beginTransmission(8); // Slave 1 address
Wire.write('A'); // Command to increase 5 degrees
Wire.endTransmission();
Wire.beginTransmission(9); // Slave 2 address
Wire.write('R'); // Command to decrease 5 degrees
Wire.endTransmission();
digitalWrite(led1, HIGH); // Turn on LED 1
delay(100); // Delay to avoid button bounce
digitalWrite(led1, LOW); // Turn off LED 1
}
if (buttonState3 == HIGH) {
// Increase 5 degrees on slave 2 and decrease 5 degrees on slave 1
Wire.beginTransmission(8); // Slave 1 address
Wire.write('R'); // Command to decrease 5 degrees
Wire.endTransmission();
Wire.beginTransmission(9); // Slave 2 address
Wire.write('A'); // Command to increase 5 degrees
Wire.endTransmission();
digitalWrite(led2, HIGH); // Turn on LED 2
delay(100); // Delay to avoid button bounce
digitalWrite(led2, LOW); // Turn off LED 2
}
delay(100); // Small delay to avoid button bounce
}