         mapLevel = maxMapLevel;
       }
       int delayMemorization = 500 + map(mapLevel, 1, maxMapLevel, 800, 0);
-      
-      //Serial.println(delayMemorization);
-      
+         
       delay(delayMemorization);
       noTone(tonePin);
       allLedOff();

int state; 
int sequence[maxLength];
int currentPlayingSeqIndex;
int stateRedButton;
int buttonStates[4] = { buttonUnknow, buttonUnknow, buttonUnknow, buttonUnknow };

void setup() {
  Serial.begin(9600);

  display.begin(SSD1306_SWITCHCAPVCC);

  pinMode(redLed, OUTPUT);
  pinMode(greenLed, OUTPUT);
  pinMode(yellowLed, OUTPUT);

      
    }
    state = statePlay;
    displayString("ripeti");
    currentPlayingSeqIndex = 0;
    
  }
  
   if (state == statePlay) {
   //if (state == 100) {
     
      if (buttonStates[0] == buttonPressed) {
        checkPressing(redButton);
        buttonStates[0] = buttonUnknow;
      } else if (buttonStates[1] == buttonPressed) {
        checkPressing(greenButton);
        buttonStates[1] = buttonUnknow;
      } else if (buttonStates[2] == buttonPressed) {
        checkPressing(yellowButton);
        buttonStates[2] = buttonUnknow;
      } else if (buttonStates[3] == buttonPressed) {
        checkPressing(blueButton);
        buttonStates[3] = buttonUnknow;
      } 
  }
  
  if (state == stateGameOver) {
    displayString("sbagliato");
    delay(1000);
    displayStringInt("punti ", level);
    state = stateEnd;
  }
  
       //manage pressing
      computeButtonState(0, redButton, redLed, NOTE_C4);  
      computeButtonState(1, greenButton, greenLed, NOTE_D4);  
      computeButtonState(2, yellowButton, yellowLed, NOTE_E4);  
      computeButtonState(3, blueButton, blueLed, NOTE_F4);
    
      pressingFeedback(false);
      
}

void pressingFeedback(boolean waitForButtonEnd) {
    if (waitForButtonEnd && buttonFeedBackStartMillis > 0 && millis() - buttonFeedBackStartMillis < 1000) {
      delay(1000 - (millis() - buttonFeedBackStartMillis));
      noTone(tonePin);
        buttonFeedBackStartMillis = 0;
        //allLedOff();
    } else {
      if (buttonFeedBackStartMillis > 0 && millis() > 1000 + buttonFeedBackStartMillis) {
        noTone(tonePin);
        buttonFeedBackStartMillis = 0;
        //allLedOff();
      }
    }
}

void displayStringInt(char * str, int i) {
    display.setTextSize(2);
    display.setTextColor(WHITE);
    display.setCursor(0,0);
    display.clearDisplay();
    display.print(str);
    display.print(i);
    display.display();
}

void displayString(char * str) {
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  display.clearDisplay();
  display.println(str);
  display.display();
}

void allLedOff() {
  digitalWrite(redLed, LOW);
