Can't swipe between RTC and some event Some ideas please?
I'm stuck and also don't judge me for how i wrote the code. I'm new into coding and still learn. So, the idea is that i want to display data and clock on lcd but when the lamp is on i want a message to be printed for 5 sec then the clock and date will be printed again... and so on.
Data from serial is comming from an esp which trigger some event wireless.Arduino receive feedback that the job has been done and then display a message on lcd. More exactly.. Using mqtt - from browser i push a button to turn on a lamp. Once the lamp is on, a message arrives at esp from the mqtt broker that lamp is on now. esp then send data to arduino using serial. and arduino should display the text " Lamp on " 

    #include &lt;Wire.h&gt; 
#include &lt;LiquidCrystal_I2C.h&gt;
#include &lt;DS3231.h&gt;

LiquidCrystal_I2C lcd(0x3F,20,4);
DS3231 rtc (SDA, SCL);

int verificare_stare_releu = A13;
char a;

void setup(){
  Serial.begin(115200);
  rtc.begin();
  lcd.init();
  lcd.backlight();
  pinMode(A13,INPUT);
}

void loop(){

  int b = analogRead(verificare_stare_releu);
    if(!Serial.available()){
    display_clock();
    }
    if(!Serial.available()){
    if(b &gt;= 900){
      lcd.print("Lamp ON ");
    }

    if( b &lt; 900 ){
      lcd.print("Lamp OFF");  
    }

    }



  if(Serial.available()&gt;0){
    a = Serial.read();
    if(a == 102){
    lcd.setCursor(0,0);
    lcd.print("Lamp ON ");
    }
  if(a == 110){
    lcd.setCursor(0,0);
    lcd.print("Lamp OFF");
  }  
  }


}

  //a = digitalRead(verificare_stare_releu);


void display_clock (){
   lcd.setCursor(0,0);
  lcd.print("Ora: "+(String)rtc.getTimeStr());
  lcd.setCursor(0,1);
  lcd.print((String)rtc.getDOWStr()+(String) rtc.getDateStr());
}
Although I still do not understand how to combine the data from the serial port with the analog input, I can show how to display a message for 5 seconds, using the Blink Without Delay example.

A boolean variable 'message' is used to prevent the normal code to use the display during the 5 seconds. The same boolean variable is used to check if 5 seconds have passed (using millis). Once the 5 seconds have passed, the boolean variable is set to 'false' and that releases the display so it can be used for normal things.

To start the 5 seconds, these two lines are required:

previousMillis = millis();
message = true;


When 'message' is set to true, the variable 'previousMillis' must be valid. Once 'message' is false, the value of 'previousMillis' is not used anymore.

The sketch can be like this:

unsigned long previousMillis;
const unsigned long interval = 5000;  // 5 seconds
bool message = false;     // true if message is displayed

void setup() {
  // the code for setup here
}

void loop() {
  if(!message) {          // message not displaying ?
    // show temperature, time, etc.
  }

  if(Serial.available() &gt; 0) {
    int a = Serial.read();
    switch(a) {
      case 102:
        lcd.setCursor(0,0);
        lcd.print("Lamp ON ");
        previousMillis = millis(); // remember this moment
        message = true;    // set boolean variable
        break;
    }
  }

  if(message) {
    if(millis() - previousMillis &gt;= interval) {
      // 5 seconds have passed ?
      message = false;    // release the display
    }
  }
}