const int switch1Pin = 2; // switch 1 connected to pin 2
const int switch2Pin = 3; // switch 2 connected to pin 3
const int led1Pin = 4; // LED 1 connected to pin 4
const int led2Pin = 5; // LED 2 connected to pin 5
void setup() {
pinMode(switch1Pin, INPUT);
pinMode(switch2Pin, INPUT);
pinMode(led1Pin, OUTPUT);
pinMode(led2Pin, OUTPUT);
}
void loop()
{
bool switch1State = digitalRead(switch1Pin); // read switch 1 state
bool switch2State = digitalRead(switch2Pin); // read switch 2 state
// XNOR conditional logic: LED turns on only if both switches are in the same state
bool led1State = !(switch1State ^ switch2State);
bool led2State = led1State;
digitalWrite(led1Pin, led1State); // turn LED 1 on/off
digitalWrite(led2Pin, led2State); // turn LED 2 on/off
delay(100); // add a small delay to debounce the switches
}