/*
1. Connect LED anode to digital pin (pin 13) on the Arduino board.
2. Connect LED catode to resiston (200-ohm) and the to the ground (GND) of the Arduino board.
3. Connect one leg of the push button to the digital pin (pin 2).
4. Connect the other leg of the push button to the ground (GND) of the Arduino board.
*/
// Define variables
int buttonPin = 2; // Digital pin where the button is connected.
int ledPin1 = 13;
int ledPin2 = 12; // Digital pin where the LED is connected.
int ledPin3 = 8;
int ledPin4 = 7;
int ledPin5 = 4;
bool buttonState = false;
int buzzerPin = 5;
void setup() {
pinMode(ledPin1, OUTPUT); // LED pin as an output.
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
pinMode(ledPin5, OUTPUT);
pinMode(buttonPin, INPUT); // Button pin as an input.
pinMode(buzzerPin, OUTPUT);
}
void loop() {
// Read the state of the button
buttonState = digitalRead(buttonPin);
// Check if the button is pressed
if (buttonState == HIGH){
digitalWrite(ledPin1, HIGH); // Turn LED on.
tone(buzzerPin, 35);
delay(3000);
digitalWrite(ledPin1, LOW);
noTone(buzzerPin);
delay(3000);
digitalWrite(ledPin2, HIGH); // Turn LED on.
tone(buzzerPin, 40);
delay(3000);
digitalWrite(ledPin2, LOW);
noTone(buzzerPin);
delay(3000);
digitalWrite(ledPin3, HIGH); // Turn LED on.
tone(buzzerPin, 45);
delay(3000);
digitalWrite(ledPin3, LOW);
noTone(buzzerPin);
delay(3000);
digitalWrite(ledPin4, HIGH); // Turn LED on.
tone(buzzerPin, 50);
delay(3000);
digitalWrite(ledPin4, LOW);
noTone(buzzerPin);
delay(3000);
digitalWrite(ledPin5, HIGH); // Turn LED on.
tone(buzzerPin, 55);
delay(3000);
digitalWrite(ledPin5, LOW);
noTone(buzzerPin);
delay(3000);
}
}