LCD menu with rotary encoder problem

Hello, for the past days i have been trying to create an interactive menu with a 1602 lcd without a l2c circuit.
The goal is to have a menu that is navigatable and has sections wich i can click on with the built in pushbutton on the rotary encoder.
For some reason my code isnt working and i have no idea why... Does anyone spot any errors that i missed?
Thanks. :confused:

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

const int inputCLK = 9;
const int inputDT = 8;
const int buttonPin = 7;

int clickState = 0;
int mode = 0;
int show = 0;

int counter = 0; 
int currentStateCLK;
int previousStateCLK; 
 

 
 void setup() { 
  
   lcd.begin(0,1);
   lcd.setCursor(1,0);
   
   pinMode (inputCLK,INPUT);
   pinMode (inputDT,INPUT);
  
   Serial.begin (9600);
   
   previousStateCLK = digitalRead(inputCLK);
 
 } 
 
 void loop() { 
  
   currentStateCLK = digitalRead(inputCLK);

    modeCheck();Serial.print(show);
    showCheck();Serial.print(" ");
    
   if (currentStateCLK != previousStateCLK){ 
       
     if (digitalRead(inputDT) != currentStateCLK) { 
     show ++;
     } else {
     show --;
     }
   } 

   previousStateCLK = currentStateCLK; 
 }

 void modeCheck() {

  if(mode == 0){
    lcd.clear();
    lcd.print("Main menu");
    mode = 1;

    }
  if(mode == 1) {  

    if(digitalRead(buttonPin) == LOW) {
      lcd.clear();
      lcd.print("listening");
        mode = 2;
        show = 1;    
      }
    }
  }

 void showCheck() {
  if(mode == 2) {
    
    if(show == 1){
        lcd.clear();
        lcd.print("Programm1");
        
        if(digitalRead(buttonPin) == LOW) {
          delay(2000);
          mode = 1;
        }
      }
      
    if(show == 2){       
        lcd.clear();
        lcd.print("Programm2");
        
        if(digitalRead(buttonPin) == LOW) {            
          delay(2000);
          mode = 1;
        }
      }
      
    if(show == 3){        
        lcd.clear();
        lcd.print("Programm3");

        if(digitalRead(buttonPin) == LOW) {            
          delay(2000);
          mode = 1;
        }
      }
    }

    if(show > 3) {show = 1;}
    if(show <1) {show = 3;}
  }

Put some more Serial.print() statements in it to see how far it gets-.

etix2002_:
For some reason my code isnt working and i have no idea why... Does anyone spot any errors that i missed?

i see several things that look confusing and would be difficult to explain in order to clarify

i think if you tried to write how you expect your code to work, some problem would become obvious.

for example, it looks like mode needs to be 2 to show any of the menu items which i believe are "Program1", "Program2", ..., but mode is only set to 2 if the buttonPin is pressed. shouldn't they always be displayed, changing as the encoder is rotated and a check of the buttonPin made independently?

don't understand the purpose of "Main menu" and "listening"

reading the encoder inputs, inc/decrementing show and handling the wraparound of show should all be together in a sub-function.

The "main menu" is there as a screen that is displayed as soon as the arduino gets power so it goes away when the buton is pressed (wich works so far) then the listening part is only there to see if the arduino changed the mode to 2 (if the button is pressed while displaying the main menu the mode gets set to 2 and the lcd displays listening becuase no programm is selected yet) so its only a way of seeing what the board does at the moment.

i have a model railroad throttle that normally displays the locomotive ID being controlled. the menu becomes active when the menu button is selected and it displays the first top level menu item. it times out after 5 seconds. the up/down buttons sequence thru other top level menu items. pressing the "select" button drops into that menu item which may be a sub-level or a leaf item that can be edited or selected.

when a menu item is selected, it makes sense to display something different indicating that that menu item is selected or exit the menu screens and the display show the state that your in.

again, i think if you problems may become obvious to you if you tried writing a detailed description of what your code does. i've discovered many of my own problems when i've had to document them