const int button1Pin = 2;
const int button2Pin = 3;
const int button3Pin = 4;
const int button4Pin = 5;
const int led1Pin = 13;
const int led2Pin = 12;
const int led3Pin = 11;
const int led4Pin = 10;
const int buzzerPin = 9; // Change this to the desired pin for the buzzer
void setup() {
pinMode(button1Pin, INPUT_PULLUP);
pinMode(button2Pin, INPUT_PULLUP);
pinMode(button3Pin, INPUT_PULLUP);
pinMode(button4Pin, INPUT_PULLUP);
pinMode(led1Pin, OUTPUT);
pinMode(led2Pin, OUTPUT);
pinMode(led3Pin, OUTPUT);
pinMode(led4Pin, OUTPUT);
pinMode(buzzerPin, OUTPUT);
}
void loop() {
// Check if button1 is pressed
if (digitalRead(button1Pin) == LOW) {
digitalWrite(led1Pin, HIGH);
} else {
digitalWrite(led1Pin, LOW);
}
// Check if button2 is pressed
if (digitalRead(button2Pin) == LOW) {
digitalWrite(led2Pin, HIGH);
} else {
digitalWrite(led2Pin, LOW);
}
// Check if button3 is pressed
if (digitalRead(button3Pin) == LOW) {
digitalWrite(led3Pin, HIGH);
} else {
digitalWrite(led3Pin, LOW);
}
// Check if button4 is pressed
if (digitalRead(button4Pin) == LOW) {
digitalWrite(led4Pin, HIGH);
} else {
digitalWrite(led4Pin, LOW);
}
// Check if all buttons are pressed
if (digitalRead(button1Pin) == LOW &&
digitalRead(button2Pin) == LOW &&
digitalRead(button3Pin) == LOW &&
digitalRead(button4Pin) == LOW) {
tone(buzzerPin, 1000); // You can adjust the frequency as needed
} else {
noTone(buzzerPin);
}
}