Can't swipe between RTC and some event
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
    }
  }
}