show message on lcd for certain amount of time before writing new message

I would like to display a message on a character lcd,

then, if a certain event happens, another appears on the screen before going back to the original message..

right now, the second message only for a very very very very small amount of time. Id like it to show up for around 5 seconds, but at the same time not block the program from moving on.

kinda like blink without delay but for lcds?

do you have any code that you have been trying?

No, i''m not sure where I'd begin with something like that. I dont need any code but some ideas so i can start to write the code would be great. I was kinda hoping there was a "standard" way of doing it.

i debating posting this in "general project guidance" initially....

I can post the code i currently have if that would help, but it doesn't attempt to delay the second message at all...

so, I usually update an LCD once a second with a function call from a millis() timer

you could use a boolean toggle that when true, shows your alternate message (calls another function) instead, for say 5 seconds...

something like this:?

int pushButton = 3;
byte lastButtonState;
int lidPin = 13;

boolean message = false;
unsigned long startMessageTime;

int hours = 23;
int minutes = 59;
unsigned long seconds = 59;
boolean toggle = false;
unsigned long startTime;
unsigned long oneSecond = 1000UL;
byte state = 0;
//
void setup()
{
  Serial.begin(115200); 
  pinMode(13, OUTPUT);
  pinMode(3, INPUT_PULLUP);
  seconds = (hours * 3600UL) + (minutes * 60UL) + seconds;
}
//
void loop()
{
  byte buttonState = digitalRead(pushButton);
  if (buttonState == LOW && lastButtonState == HIGH)
  {
    message = true;
    startMessageTime = millis();
  }
  lastButtonState = buttonState;
  if (millis() - startTime >= oneSecond)
  {
    if (message == true)
    {
      writeMessage();
    }
    else
    {
      updateDisplay();
    }
    seconds--;
    startTime += oneSecond;
  }
}
//
void updateDisplay()
{
  int displayHrs = seconds / 3600;
  if (displayHrs < 10)  
  {
    Serial.print("0");
  }
  Serial.print(displayHrs);
  Serial.print(":");
  int displayMins = (seconds % 3600) / 60;
  if (displayMins < 10)
  {
    Serial.print("0");
  }
  Serial.print(displayMins);
  Serial.print(":");
  unsigned long displaySecs = seconds % 60;
  if (displaySecs < 10)
  {
    Serial.print("0");
  }
  Serial.println(displaySecs);
}
//
void writeMessage()
{
  if (millis() - startMessageTime <= 5000UL)
  {
    Serial.println("Message");
  }
  else
  {
    message = false;
  }
}

ok, let me try something like that. I will update once i have tried it.

thanks!

Edit:
where are you writing to the LCD at? are you just using serial as a display in that example?

Qdeathstar:
where are you writing to the LCD at? are you just using serial as a display in that example?

yes, just using the serial monitor as an example.

kinda like blink without delay but for lcds?

That is essentially the technique that you should use.

  • You will initially have the first message displayed.
  • When the event happens you will display the new message and start counting milliseconds
  • If the elapsed time is not up you will just continue doing whatever you should be doing
  • If the elapsed time is up you will display the original message again and continue doing whatever you should be doing .

Don