int ledPins[] = {2, 4, 6}; // Replace with your LED pin numbers
int switchPins[] = {8, 9, 10}; // Replace with your switch pin numbers
int buzzerPin = 12; // Replace with your buzzer pin number
int currentPattern = 0; // Tracks the currently active LED pattern
void setup() {
for (int i = 0; i < 3; i++) {
pinMode(ledPins[i], OUTPUT);
pinMode(switchPins[i], INPUT_PULLUP);
}
pinMode(buzzerPin, OUTPUT);
// Initialize all LEDs to off state
for (int i = 0; i < 3; i++) {
digitalWrite(ledPins[i], LOW);
}
noTone(buzzerPin); // Turn off the buzzer
Serial.begin(9600); // Initialize serial communication for debugging
}
void loop() {
for (int i = 0; i < 3; i++) {
if (digitalRead(switchPins[i]) == LOW) {
// Cycle through different LED patterns and buzzer sounds
currentPattern = (currentPattern + 1) % 3;
activatePattern(currentPattern);
delay(500); // Debounce the switch
}
}
}
void activatePattern(int pattern) {
// Turn off all LEDs
for (int i = 0; i < 3; i++) {
digitalWrite(ledPins[i], LOW);
}
noTone(buzzerPin); // Turn off the buzzer
// Implement different LED patterns and buzzer sounds based on the 'pattern' parameter
if (pattern == 0) {
// Pattern 1: LEDs in sequence
for (int i = 0; i < 3; i++) {
digitalWrite(ledPins[i], HIGH);
delay(500);
digitalWrite(ledPins[i], LOW);
}
// Play a buzzer sound
tone(buzzerPin, 1000, 500); // Frequency and duration
} else if (pattern == 1) {
// Pattern 2: Flashing LEDs
for (int i = 0; i < 3; i++) {
digitalWrite(ledPins[i], HIGH);
}
// Play a different buzzer sound
tone(buzzerPin, 1500, 500); // Frequency and duration
} else if (pattern == 2) {
// Pattern 3: Random LED pattern
for (int i = 0; i < 5; i++) {
int randomLED = random(3);
digitalWrite(ledPins[randomLED], HIGH);
delay(300);
digitalWrite(ledPins[randomLED], LOW);
}
// Play another buzzer sound
tone(buzzerPin, 2000, 500); // Frequency and duration
}
}