          displayWrite("sbagliato");
          state = stateEnd;
        }
-      delay(1000);
-      noTone(tonePin);
-      allLedOff();
-    
+                delay(1000);
+          noTone(tonePin);
+          allLedOff();
+
 }
 
 boolean pressed(int button) {

      if (button == 2) sequence[i] = yellowButton;
      if (button == 3) sequence[i] = blueButton;
    }
    
    //play
    displayWrite("memorizza");
    for (int i = 0; i < level; i++) {
    int button = sequence[i];
      delay(300);
      digitalWrite(button, HIGH);
      if (button == redButton) { tone(tonePin, NOTE_C4); digitalWrite(redLed, HIGH); } 
      if (button == greenButton) { tone(tonePin, NOTE_D4); digitalWrite(greenLed, HIGH); } 
      if (button == yellowButton) { tone(tonePin, NOTE_E4); digitalWrite(yellowLed, HIGH); } 
      if (button == blueButton) { tone(tonePin, NOTE_F4); digitalWrite(blueLed, HIGH); } 
      
      delay(1000);
      noTone(tonePin);
      allLedOff();
      
    }
    state = statePlay;
    displayWrite("ripeti");
    currentPlayingSeqIndex = 0;
    
  } 
  
  
  /*
  Serial.print(analogRead(redButton));
  Serial.print(analogRead(greenButton));
  Serial.print(analogRead(yellowButton));
  Serial.println(analogRead(blueButton));
  */
  
    if (pressed(redButton) && (state == statePlay)) {
     checkPressing(redLed, NOTE_C4, redButton); 
  } else if (pressed(greenButton) && (state == statePlay)) {
    checkPressing(greenLed, NOTE_D4, greenButton);
  } else if (pressed(yellowButton) && (state == statePlay)) {

  state = stateNewLevel;
  
  randomSeed(analogRead(A5));
  
  //initial set
  for (int i = 0 ; i < level; i++) {
    sequence[i] = redButton;
  }
  
}

