// Déclaration des constantes et variables

const int PinTone = 8;
const int PinButton = 12;
const int Notes[] = {262,294,330,262,294,330,349,392,330,349,392};
const int NoteDurations[] = {4,4,4,4,4,4,4,8,4,4,8};

int State = 0;
int ValButton = 0;
int OldValButton = 0;


// Initialisation des entrées et sorties

void setup() {
  pinMode (PinButton, INPUT);
}


// Fonction principale en boucle

void loop() {
  ValButton = digitalRead(PinButton);
  delay(10);
  if (ValButton == HIGH and OldValButton == LOW) {
    State = 1 - State;
  }
  if (State == 1) {
    for(int i = 0 ; i < 11 ; i++)
    {
      int NoteDuration = int(1000/NoteDurations[i]);
      tone(PinTone, Notes[i], NoteDuration);
      delay(1.3*NoteDuration);

      ValButton = digitalRead(PinButton);
      delay(10);
      if (ValButton == HIGH and OldValButton == LOW) {
      State = 1 - State;
      break;
      }
      OldValButton = ValButton; 
    } 
  }
  else {
    noTone(PinTone);
  }
  OldValButton = ValButton;   
}

