// There are 4 buttons, 4 associated LEDs, and 4 MP3 players const int PinIn[] = {A0, A1, A2, A3}; // Input pins connected to buttons const int LEDPins[] = {12, 8, 5, 2}; // LED pins for each button const int PWMPins[] = {11, 9, 6, 3}; // PWM pins for each MP3 module bool timer(int index) {static unsigned long data[3][2] = {{0,300000},{0,1000},{0,2000}}; if (millis()-data[index][0]>data[index][1]){data[index][0]=millis();return true;}return false;} void setup() { for (int i = 0; i < 4; i++) { pinMode(PinIn[i], INPUT_PULLUP); pinMode(LEDPins[i], OUTPUT); digitalWrite(LEDPins[i], HIGH); // 12v LED powered by buck converter with enable pin pinMode(PWMPins[i], OUTPUT); analogWrite (PWMPins[i], 0);} // short tiny pulse will activate the MP3 module for (int j=0;j<30;j++){for (int x=0;x<4;x++){digitalWrite(LEDPins[x],HIGH);delay(40);digitalWrite(LEDPins[x],LOW);delay(20);}}} void loop() {if (timer(0)) {dobutton(random(4));} // play a random MP3 every 5 minutes for (int group=0;group<4;group++){if (digitalRead(PinIn[group])==LOW) {dobutton(group);}}} void dobutton(int z) {analogWrite(PWMPins[z],1); delay(20); analogWrite(PWMPins[z],0); for (int j = 0; j < 30; j++) {digitalWrite(LEDPins[z], HIGH);delay(30); digitalWrite(LEDPins[z],LOW); delay(30);}}