#define NOTE_B0 31
const byte redSW=2;
const byte blueSW=3;
const byte grennSW=4;
const byte yellowSW=5;
const byte whiteSW=6;
const byte swCount=5;
const byte speaker= 9;
bool isBoom=false;
const byte swPins[] = {
redSW,blueSW,grennSW,yellowSW,whiteSW};
int ledEnd=8;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
for (byte pin = 0; pin < swCount; pin++) {
pinMode(swPins[pin], INPUT_PULLUP);
}
pinMode(speaker, OUTPUT);
pinMode(ledEnd, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
check();
delay(500);
}
void check(){
if (isBoom)
return;
byte sumPres=0;
for (byte pin = 0; pin < swCount; pin++) {
int redVal=digitalRead(swPins[pin]);
if (redVal==LOW)
{
if(pin >0 && digitalRead(swPins[pin-1])==HIGH){
BOOOM();
break;
}
sumPres++;
}
}
Serial.println(sumPres);
if(sumPres==swCount){
digitalWrite(ledEnd, HIGH);
}
}
void BOOOM(){
Serial.println("BOOM");
isBoom=true;
tone(speaker, NOTE_B0);
delay(3000);
noTone(speaker);
}