Rottary encoder /menu

Hello,
I wish to make a menu system so i can control and change settings of different sensors
My first step is to make a working menu using the rottary encoder.
First approach was with if statement and counter on Rottary,
Problem lcd would flicker and printing only the first line

Then tried using cases failed to make it work
Then thought to use void loops i also failed.

Please what is the best approach for it on a arduino nano?

What have you tried? POST THE SKETCH.
Not posting your code is like asking a car mechanic to diagnose and fix your car over the phone. Not gonna' happen.

If you post your code as described in the how to use this forum sticky, more members will read it.
Post your sketch (code), schematic in CAD or a picture of a hand drawn circuit in jpg or png. PLEASE- not a pretty Fritzing picture.

@byronas: correct spelling is "rotary"

Using 'if' statement should be OK for this purpose. There is a high possibility of missing edges/clicks of the encoder if it is moved quickly, but when selecting from a menu, this is not normally a problem, because the user gets continuous visual confirmation of the currently selected menu item. They may not notice some missing edges/clicks.

i found a ready code by ELECTRONOOBS that seems very close to what i need
i am now having problems making it work with an arduino NANO

i am having problem with these lines!!! (i think)

 PCICR |= (1 << PCIE0);    //enable PCMSK0 scan                                                 
  PCMSK0 |= (1 << PCINT0);  //Set pin (D8)trigger an interrupt on state change. 
  PCMSK0 |= (1 << PCINT1);  //Set pin (D9) trigger an interrupt on state change.  
  DDRB &= B11111110;        //8, 9 as input for the encoder clock and data pins

  Last_State =   (PINC & B00000001); //pin 8 state (clock pin)?
//Interruption vector

ISR(PCINT0_vect){
  
  clk_State =   (PINB & B00000001); //pin 8 state, clock pin? 
  dt_State  =   (PINB & B00000010); 
  if (clk_State != Last_State){     
     // If the data state is different to the clock state, that means the encoder is rotating clockwise
     if (dt_State != clk_State) { 
       counter ++;
     }
     else {
       counter --;
     } 
   } 
   Last_State = clk_State; // Updates the previous state of the data with the current state
  
}

the full code is here:

http://www.electronoobs.com/eng_arduino_tut22_code6.php

byronas:
the full code is here:

Voice menu encoder arduino LCD

In general, people here will not download code. Especially php code.

If you post your code- ALL OF IT- as described in the how to use this forum sticky, more members will read it.

I tried but it exceeds the 9000 characters.
And it was not allowed.
I will try again in the afternoon.

I think that the problem is in the ports of the nano
that can handle interupts.

/*
  Menu with voice and rotary encoder
  http://www.electronoobs.com/eng_arduino_tut22.php
  http://www.youtube.com/c/ELECTRONOOBS
 */
 
//Inport the libraries
#include <DFMiniMp3.h>
//LCD config
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3f,20,4);  //sometimes the LCD adress is not 0x3f. Change to 0x27 if it dosn't work.



////////////////////Serial prints for the DFplayer/////////////////////////////
class Mp3Notify
{
public:
  static void OnError(uint16_t errorCode)
  {
    // see DfMp3_Error for code meaning
    Serial.println();
    Serial.print("Com Error ");
    Serial.println(errorCode);
  }

  static void OnPlayFinished(uint16_t globalTrack)
  {
    Serial.println();
    Serial.print("Play finished for #");
    Serial.println(globalTrack);   
  }

  static void OnCardOnline(uint16_t code)
  {
    Serial.println();
    Serial.print("Card online ");
    Serial.println(code);     
  }

  static void OnCardInserted(uint16_t code)
  {
    Serial.println();
    Serial.print("Card inserted ");
    Serial.println(code); 
  }

  static void OnCardRemoved(uint16_t code)
  {
    Serial.println();
    Serial.print("Card removed ");
    Serial.println(code);  
  }
};


DFMiniMp3<HardwareSerial, Mp3Notify> mp3(Serial);
/////////////////////////////////////////////////////////








//Vectors for musical note and arrow
uint8_t note[8]  = {0x02, 0x03, 0x02, 0x0e, 0x1e, 0x0c, 0x00, 0x00};
uint8_t arrow[8] = {0x0, 0x04 ,0x06, 0x1f, 0x06, 0x04, 0x00, 0x00};

//Variables for the menu encoder
int counter = 0; 
int page=1;
int Ready=1;
int submenu=0;
int last_counter = 0; 
bool clk_State;
bool Last_State; 
bool dt_State;  
int pushed = 0;

//The pin for the push button
#define push 10

void setup() {
  pinMode (push,INPUT);       //Define the pin as input
  
  lcd.init();                 //Init the LCD
  lcd.backlight();            //Activate backlight
  lcd.createChar(0, note);    //Create the note symbol
  lcd.createChar(1, arrow);   //Create the arrow symbol
  lcd.home();                 //Home the LCD
  
  PCICR |= (1 << PCIE0);    //enable PCMSK0 scan                                                 
  PCMSK0 |= (1 << PCINT0);  //Set pin D8 trigger an interrupt on state change. 
  PCMSK0 |= (1 << PCINT1);  //Set pin D9 trigger an interrupt on state change.  
  DDRB &= B11111100;        //8, 9 as input for the encoder clock and data pins

  Last_State =   (PINB & B00000001); //pin 8 state (clock pin)? 
  
  //Prepare the DFplayer module comunication and settings  
  Serial.begin(115200);  
  mp3.begin();
  uint16_t volume = mp3.getVolume();
  mp3.setVolume(20);  
  uint16_t count = mp3.getTotalTrackCount();

  //Print the initial text. Delete these lines if you don't want that
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.write(0);  
  lcd.print(" ELECTRONOOBS ");
  lcd.write(0);
  lcd.setCursor(0,1);  
  lcd.print(" Coffee machine ");
  delay(3000);

  //Print the first page menu.
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.write(1);  
  lcd.print("Choose coffee");
  lcd.setCursor(0,1);  
  lcd.print(" Sugar level");
}





//Void for the DFplayer to play sounds
void waitMilliseconds(uint16_t msWait)
{
  uint32_t start = millis();  
  while ((millis() - start) < msWait)
  {
    mp3.loop(); // calling mp3.loop() periodically allows for notifications to be handled without interrupts
    delay(1);
    }
  }

















void loop() { 
  
  if((last_counter > counter) || (last_counter < counter)  || pushed) //Only print on the LCD when a step is detected or the button is pushed.
  {
    Ready=1;

    //First page of the menu
    if(submenu == 0)
    {  
      if(0 <= counter && counter < 5)
      {
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.write(1);  
        lcd.print("Choose coffee");
        lcd.setCursor(0,1);  
        lcd.print(" Sugar level");
        page=1;
        if(pushed)
        {
          mp3.playMp3FolderTrack(1);  // play coffe select sound
          pushed=0;
        }
      }
    
      if(5 < counter && counter < 10)
      {
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print(" Choose coffee");
        lcd.setCursor(0,1);
        lcd.write(1);   
        lcd.print("Sugar level");
        page=2;
        if(pushed)
        {
          mp3.playMp3FolderTrack(2);  
          pushed=0;
        }     
      }
      
      if(10 < counter && counter < 15)
      {
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.write(1);  
        lcd.print("Backlight");
        lcd.setCursor(0,1);  
        lcd.print(" Volume");
        page=3;
        if(pushed)
        {
          mp3.playMp3FolderTrack(3);  
          pushed=0;
        }       
      }
    
      if(15 < counter && counter < 20)
      {
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print(" Backlight");
        lcd.setCursor(0,1);
        lcd.write(1);   
        lcd.print("Volume");
        page=4;
        if(pushed)
        {
          mp3.playMp3FolderTrack(4);  
          pushed=0;
        }  
     }
  }//submenu = 0;

}
//Second page of the menu
    if(submenu == 1)
      {  
        if(0 <= counter && counter < 5)
        {
          lcd.clear();
          lcd.setCursor(0,0);
          lcd.write(1);  
          lcd.print("Latte");
          lcd.setCursor(0,1);  
          lcd.print(" Cappuccino");
          page=1;
          pushed=0;    
        }
      
        if(5 < counter && counter < 10)
        {
          lcd.clear();
          lcd.setCursor(0,0);
          lcd.print(" Latte");
          lcd.setCursor(0,1);
          lcd.write(1);   
          lcd.print("Cappuccino");
          page=2;
          pushed=0;      
        }
      
        if(10 < counter && counter < 15)
        {
          lcd.clear();
          lcd.setCursor(0,0);
          lcd.write(1);  
          lcd.print("Americano");
          lcd.setCursor(0,1);  
          lcd.print(" Back");
          page=3;
          pushed=0;      
        }
      
        if(15 < counter && counter < 20)
        {
          lcd.clear();
          lcd.setCursor(0,0);
          lcd.print(" Americano");
          lcd.setCursor(0,1);
          lcd.write(1);   
          lcd.print("Back");
          page=4;
          pushed=0;        
        }
      }//submenu = 1;




    //Third page of the menu
    if(submenu == 2)
    {  
      if(0 <= counter && counter < 5)
      {
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.write(1);  
        lcd.print("25%");
        lcd.setCursor(0,1);  
        lcd.print(" 50%");
        page=1;
        pushed=0;    
      }
    
      if(5 < counter && counter < 10)
      {
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print(" 25%");
        lcd.setCursor(0,1);
        lcd.write(1);   
        lcd.print("50%");
        page=2;
        pushed=0;      
      }
    
      if(10 < counter && counter < 15)
      {
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.write(1);  
        lcd.print("75%");
        lcd.setCursor(0,1);  
        lcd.print(" 100%");
        page=3;
        pushed=0;      
      }
    
      if(15 < counter && counter < 20)
      {
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print(" 75%");
        lcd.setCursor(0,1);
        lcd.write(1);   
        lcd.print("100%");
        page=4;
        pushed=0;        
      }
    }//submenu = 2;








    //Forth page of the menu
    if(submenu == 3)
    {  
      if(0 <= counter && counter < 5)
      {
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.write(1);  
        lcd.print("ON");
        lcd.setCursor(0,1);  
        lcd.print(" OFF");
        page=1;
        pushed=0;    
      }
    
      if(5 < counter && counter < 10)
      {
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print(" ON");
        lcd.setCursor(0,1);
        lcd.write(1);   
        lcd.print("OFF");
        page=2;
        pushed=0;      
      }    
    }//submenu = 3;
  
  
    if(submenu == 4)
    {  
      if(0 <= counter && counter < 5)
      {
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.write(1);  
        lcd.print("25%");
        lcd.setCursor(0,1);  
        lcd.print(" 50%");
        page=1;
        pushed=0;    
      }
    
      if(5 < counter && counter < 10)
      {
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print(" 25%");
        lcd.setCursor(0,1);
        lcd.write(1);   
        lcd.print("50%");
        page=2;
        pushed=0;      
      }
    
      if(10 < counter && counter < 15)
      {
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.write(1);  
        lcd.print("75%");
        lcd.setCursor(0,1);  
        lcd.print(" 100%");
        page=3;
        pushed=0;      
      }
    
      if(15 < counter && counter < 20)
      {
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print(" 75%");
        lcd.setCursor(0,1);
        lcd.write(1);   
        lcd.print("100%");
        page=4;
        pushed=0;        
      }
    }//submenu = 4;

  
  }//end of the MENU prints on the LCD

So... this code is unchanged from what you found on the "electro noobs" page? And you think it might not be compatible with your Nano? What type of Arduino was the code written for? If it was Uno, then no problem, Uno and Nano have the exact same chip. If it was written for Mega, Leonardo, Due, then perhaps you are correct.