const int buzzerPin = 11; // Digital pin connected to buzzer
const int ledPins[] = {2, 4, 9,13}; // Digital pins connected to LEDs
const int numLeds = 4; // Number of LEDs
void setup() {
pinMode(buzzerPin, OUTPUT); // Set buzzer pin as an output
for (int i = 0; i < numLeds; i++) {
pinMode(ledPins[i], OUTPUT); // Set each LED pin as an output
}
}
void loop() {
tone(buzzerPin,500); // buzzer ring
delay(500); // Buzzer on for 500ms
// Dancing lights effect
for (int i = 0; i < numLeds; i++) {
digitalWrite(ledPins[i], HIGH); // Turn on the LED
delay(100); // Wait for 100ms
digitalWrite(ledPins[i], LOW); // Turn off the LED
}
noTone(buzzerPin); // Turn off the buzzer
delay(500); // Buzzer off for 500ms
}