I'm making a project where you have a led matrix, LCD and 7 different sensors. Each sensor will display a different message to the matrix and has it's own sub menu on the LCD.
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 void loop when the pin has changed) Also a select button is used to run the program of a menu item.( a sensor program like prg_Pong(), prg_Flame());
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 flicker because of the interrupt on the rotary encoder pin) but when I press the button to run for ex prg_Pong() the lcd prints message running pong but the message is flickering and the message on the led matrix is good (static).
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 flicker at the delay time and the menu item "running pong" doesn't flicker anymore.
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.
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 (mai n 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]);
}
}