arduino mega LCD and leOS2

Hi guys, I’m working on a new project with Arduino Mega. And i have a problem, I’m using:

  • LCD 20x4
  • RTC DS1307
  • Shield SD Card
  • Keypad 4x4

I exsplain my project.
When I select the right code, Arduino turns on a relay and it starts a timer it using the library leOS2.
After when I press “D” on the keypad Arduino turns off the relay and saves the timer with the date in SD card.
Ok, this program works very well if I read the data with the Serial Monitor. But when I use LCD, it works well to some hours and after the LCD doesn’t work, it crashes and it doesn’t show anything.
Do you have any advices? I can’t understand what is the problem.
I attach my code.

while(num > -1){

    //Riazzero la password
    pass[0] = 0;
    pass[1] = 0;
    pass[2] = 0;
    pass[3] = 0;

    keypressed = myKeypad.getKey();
    if(num < 20 && num > -1){
      lcd.setCursor(0,0);
      lcd.print("Accesso effettuato! ");
      lcd.setCursor(0,1);
      lcd.print("Utente ");
      lcd.print(num + 1);
      lcd.print("            ");
      myOS.restartTask(updateRTC);
      lcd.setCursor(0,3);
      lcd.print("      ");
      lcd.print("'D' per uscire");
      if (keypressed != NO_KEY)
      {
        Serial.print(keypressed);
        pass_nuova = keypressed;
      }

      delay(500);

      if(pass_nuova == 'D'){
        myOS.pauseTask(updateRTC);
        lcd.setCursor(0,1);
        lcd.print("                    ");
        lcd.setCursor(0,2);
        lcd.print("                    ");
        lcd.setCursor(0,3);
        lcd.print("                    ");
        delay(500);
        lcd.clear();

Thanks :grinning:

project.ino (33 KB)