Flikkering LCD and led matrix

Hello guys

I’m making a project where you have a led matrix, LCD and different sensors. Each sensor will display a different message to the matrix. I’ve created a menu for switching between the sensors. A rotary encoder is used to navigate in the menu. (A pin has an interrupt on change for executing only the loop when a value has changed) Also a select button is used to run the sensor program

I want to display the menu items on the LCD (no I2C). Now my problem is my main menu items are displayed correctly (with no flikker because of the interrupt on the rotary encoder pin)

but when I press the button to run for ex prg_Pong() the LCD message begins to flikker. I’ve found a solution by adding a delay(300); in the loop after drawMenu but when I do that and enter prg_Pong();
the message on the led matrix starts to flikker at the delay time.

I’ve uploaded the full program. The functions displayData(),mtx_clear() are used for the led matrix and they are working. Because when I remove the functionality of the LCD the message is displayed correctly.

I also uploaded an image and a video of the problem

void loop() {
  drawMenu(RotaryEncoder());
 delay(300);
}


void drawMenu(byte rotaryPosition) {
  stateBtnSelect = digitalRead(BTN_SELECT);
  if (stateBtnSelect == HIGH && previousBtnState == LOW && millis() - time > debounce) {
    if (state == HIGH)
      state = LOW;
    else
      state = HIGH;
    time = millis();
  }
  previousBtnState = stateBtnSelect;

  //Switch the value of the rotary encoder
  switch (rotaryPosition) {
    case 0:
      displayMenuItem(0);
      if (state == HIGH) {
        prg_Pong();
      }
      break;
    case 1:
      displayMenuItem(1);
      if (state == HIGH) {
        prg_Ascroll();
      }
      break;
    case 2:
      displayMenuItem(2);
      if (state == HIGH) {
        prg_Clock();
      }
      break;
    case 3:
      displayMenuItem(3);
      if (state == HIGH) {
        prg_Flame();
      }
      break;
    case 4:
      displayMenuItem(4);
      if (state == HIGH) {
        prg_Heartbeat();
      }
      break;
    default:
      break;
  }
}


//Display a menu item
void displayMenuItem(byte item)
{
  //menu strings (main categories)
  String menuItems[MAX_MENU_ITEMS] = {"Pong game", "A. Scroller", "Clock", "Flame/temp", "Heartbeat"};
 lcd.clear();
  lcd.setCursor(6, 0);
  lcd.print("Menu");
  lcd.setCursor(0, 1);
  lcd.write(byte(0));
  lcd.print(menuItems[item]);
}


void prg_Pong()
{
  lcd.clear();
  delay(100);
  lcd.print("run pong");
  mtx_clear();

  //print cirlce once
  MessageEncoder(ReturnLetter(24), BitStream);
  for (int j = 0; j < 8; j++)
  {
    displayData(~BitStream[j] & Kolommen[j]);
  }
}

Alphabet.zip (6.72 KB)

Archive.zip (314 KB)

lcd.clear();

Instead of clearing the display and printing the entire menu for each update, just update what has changed.