       if (button == 2) sequence[i] = yellowButton;
       if (button == 3) sequence[i] = blueButton;
     }
-      
+    
     //play
-    displayWrite("memorizza");
+    displayString("memorizza");
     for (int i = 0; i < level; i++) {
       int button = sequence[i];
       if (button == redButton) { tone(tonePin, NOTE_C4); digitalWrite(redLed, HIGH); } 

    sequence[i] = redButton;
  }
  
  stateRedButton = 0;
  
}

void loop() {
  
    computeButtonStates(0, redButton, redLed);  
    computeButtonStates(1, greenButton, greenLed);  
    computeButtonStates(2, yellowButton, yello);  
    computeButtonStates(3, blueButton);  
  
  if (state == stateNewLevel) {
    level ++;
    String a = "livello ";
     a += level;
    displayWrite(a);
    delay(2000);
    state = statePrepare;
  }
  
  if (state == stateEnd) {
    String a = "punti ";
    a += level;
    displayWrite(a);
  }

  if (state == statePrepare) {
    //set
    for (int i = level - 1 ; i < level; i++) {

}


void computeButtonState(int index, int button, int led, int note) {
      int tmpVal = analogRead(button);
      delay(20);
      if (tmpVal > 900) {
        allLedOff();
        buttonStates[index] = buttonDown;
        digitalWrite(led, HIGH);
        tone(tonePin, note);
        buttonFeedBackStartMillis = millis();
      } else {
        if (buttonStates[index] == buttonDown) {
          buttonStates[index] = buttonPressed;
          allLedOff();
        }
      }  
}


void checkPressing(int button) {
  if (sequence[currentPlayingSeqIndex] == button) {
    currentPlayingSeqIndex ++;
    if (currentPlayingSeqIndex >= level) {
      state = stateNewLevel;
      pressingFeedback(true);
    }
  } else {
    state = stateGameOver;
    pressingFeedback(true);
  }
  
}
