Cycling through multiple alarms

I am working on a project that will monitor several parameters (~6) and will display any exceedances on an LCD screen.

There is no problem with displaying one exceedance, but how do I deal with multiple exceedances so that each exceedance shows on the screen, for, let's say, 2 seconds, as opposed to all the exceedances flashing on the screen as the loop cycles?

The system has to keep running and doing calculations while these errors are displayed, so having a delay and then cycling to the next alarm won't work.

Can someone point me in the right direction if there is a simple algorithm that others have used to accomplish the same thing?

As usual, take a look at the blink without delay example in the IDE, without delay.

A LCD display can have a few characters that you can make yourself. You could make an alarm character.
If it is only 6, then I would put all of them on the display.
Design your own character: LCD Custom Character Generator.

You are going to need the Blink Without Delay sooner or later. It can be used for all kinds of timing and sequences without disturbing the rest of the sketch.

You can set it up something like this. You can call the updateDisplay() function as often as you like, but it won't actually update until the fixed duration has expired.

const int maxMessages = 6;

const char *Msgs[maxMessages] = {
  "Error msg 1",
  "Error msg 2",
  "Error msg 3",
  "Error msg 4",
  "Error msg 5",
  "Error Msg 6"

bool active[maxMessages];
char OKMsg[] = "All good";

void setup() {


void loop() {

  // to work, calculations, etc
  // based on sensors, set error messages as active or not


void updateDisplay()
  static unsigned long lastTime;
  const unsigned long duration = 2000;  // time for each message
  static byte currentIdx;

  bool ok = true;

  if ( millis() - lastTime >= duration ) {
    // display next active message
    lastTime = millis();
    // TODO: clear display or set cursor, etc.
    // lcd.setCursor(x,y);
    for ( int i = 0; i < maxMessages; ++i ) {
      currentIdx = (currentIdx + 1) % maxMessages;
      if ( active[currentIdx] == true ) {
        // display message
        // lcd.print(OKMsg);
        ok = false;
    if ( ok == true ) {
      // display message
      // lcd.print(Msgs[currentIdx]);

Excellent. Thanks blh64. That did the trick.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.