#define speakerPin 4
#define relayPin 3

int first = 0;
int second = 0;
int third = 0;

int bound = 780;
int firstbound = 740;
bool done = false;
bool openSong = false;


void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(speakerPin, OUTPUT);
  pinMode(relayPin, OUTPUT);
  digitalWrite(relayPin, HIGH);
}

void loop() {
  // put your main code here, to run repeatedly:
  first = analogRead(A0);
  second = analogRead(A1);
  third = analogRead(A2);

  if(first > bound && second > bound && third > firstbound){
    done = true;
  }

  if(done == true){
      if(openSong == false){
      songOpen();
      openSong = true;
      digitalWrite(relayPin, LOW);
    } 
    if(first < 10 && third < 650 && third > 570  && second < 10){
      //for reset 21-3 or 21-c
      done = false;
      openSong = false;
      digitalWrite(relayPin, HIGH);
      songReset();
    }

  }

Serial.print("First: ");
Serial.println(first);
Serial.print("Second: ");
Serial.println(second);
Serial.print("Third: ");
Serial.println(third);

}

void songReset(){
  tone(speakerPin, 293);
  delay(160);
  noTone(speakerPin);
  delay(7);
  tone(speakerPin, 293);
  delay(160);
  noTone(speakerPin);
  delay(7);
  tone(speakerPin, 293);
  delay(167);
  tone(speakerPin, 392);
  delay(1000);
  tone(speakerPin, 587);
  delay(1000);
  tone(speakerPin, 523);
  delay(167);
  tone(speakerPin, 493);
  delay(167);
  tone(speakerPin, 440);
  delay(167);
  tone(speakerPin, 784);
  delay(1000);
  tone(speakerPin, 587);
  delay(500);
  tone(speakerPin, 523);
  delay(167);
  tone(speakerPin, 493);
  delay(167);
  tone(speakerPin, 440);
  delay(167);
  tone(speakerPin, 784);
  delay(1000);
  tone(speakerPin, 587);
  delay(500);
  tone(speakerPin, 523);
  delay(167);
  tone(speakerPin, 493);
  delay(167);
  tone(speakerPin, 523);
  delay(167);
  tone(speakerPin, 440);
  delay(1000);
/*
  tone(speakerPin, 659);
  delay(300);
  tone(speakerPin, 587);
  delay(300);
  tone(speakerPin, 523);
  delay(30);
  tone(speakerPin, 659);
  delay(300);
  tone(speakerPin, 659);
  delay(300);
  tone(speakerPin, 587);
  delay(300);
  tone(speakerPin, 523);
  delay(300);
  tone(speakerPin, 659);
  delay(300);
  tone(speakerPin, 659);
  delay(300);
  tone(speakerPin, 587);
  delay(300);
  tone(speakerPin, 523);
  delay(300);
  tone(speakerPin, 659);
  delay(300);
  tone(speakerPin, 659);
  delay(300);
  tone(speakerPin, 587);
  delay(300);
  tone(speakerPin, 523);
  delay(300);
  tone(speakerPin, 659);
  delay(300);
  tone(speakerPin, 659);
  delay(300);
  tone(speakerPin, 587);
  delay(300);
  tone(speakerPin, 523);
  delay(300);
  tone(speakerPin, 659);
  delay(300);
  tone(speakerPin, 659);
  delay(300);
  tone(speakerPin, 587);
  delay(300);
  tone(speakerPin, 523);
  delay(300);
  tone(speakerPin, 659);
  delay(300);
  tone(speakerPin, 659);
  delay(300);
  tone(speakerPin, 587);
  delay(300);
  tone(speakerPin, 523);
  delay(300);
  tone(speakerPin, 659);
  delay(300);
  */
  noTone(speakerPin);
}

void songOpen(){
  tone(speakerPin, 587);
  delay(500);
  tone(speakerPin, 659);
  delay(500);
  tone(speakerPin, 523);
  delay(500);
  tone(speakerPin, 261);
  delay(500);
  tone(speakerPin, 392);
  delay(500);
  /*
  tone(speakerPin, 523);
  delay(100);
  tone(speakerPin, 587);
  delay(100);
  tone(speakerPin, 659);
  delay(100);
  tone(speakerPin, 523);
  delay(100);
  tone(speakerPin, 587);
  delay(100);
  tone(speakerPin, 659);
  delay(100);
  tone(speakerPin, 523);
  delay(100);
  tone(speakerPin, 587);
  delay(100);
  tone(speakerPin, 659);
  delay(100);
  tone(speakerPin, 523);
  delay(100);
  tone(speakerPin, 587);
  delay(100);
  tone(speakerPin, 659);
  delay(100);
  tone(speakerPin, 523);
  delay(100);
  tone(speakerPin, 587);
  delay(100);
  tone(speakerPin, 659);
  delay(100);
  tone(speakerPin, 523);
  delay(100);
  tone(speakerPin, 587);
  delay(100);
  tone(speakerPin, 659);
  delay(100);
  tone(speakerPin, 523);
  delay(100);
  tone(speakerPin, 587);
  delay(100);
  tone(speakerPin, 659);
  delay(100);
  tone(speakerPin, 587);
  delay(200);
  tone(speakerPin, 523);
  delay(300);
  */
  noTone(speakerPin);
}
