Lcd Clock almost finished.

my project is almost there. Here is the complete code. Just need some help with the following.

I can navigate the menu but when I break out of the menu to change any of the RTC parameters the encoder just navigates the menu again. I can only change parameters of the RTC using the encoder push button. What I want is to change the parameters using the encoder.

#include <Wire.h>
#include <Rtc_Pcf8563.h>
#include <MenuBackend.h> //MenuBackend library - copyright by Alexander Brevig
#include <LiquidCrystal.h> //this library is included in the Arduino IDE

const int encoderPushButton = 45; // pin for the Enter button
const int buttonPinEsc = 42; // pin for the Esc button

int encoder0PinA = 2;
int encoder0PinB = 3;
int encoder0Pos = 0;
int encoder0PinALast = LOW;
int n = HIGH;

int menuRoot = true;// A global flag. true = root (top) menu and display clock. false = don't display clock

int lastButtonPushed = 0;
int lastButtonEnterState = LOW; // the previous reading from the Enter input pin
int lastButtonEscState = LOW; // the previous reading from the Esc input pin
long lastEnterDebounceTime = 0; // the last time the output pin was toggled
long lastEscDebounceTime = 0; // the last time the output pin was toggled
long debounceDelay = 150; // the debounce time

LiquidCrystal lcd(7,8,9,10,11,12);

Rtc_Pcf8563 rtc;//init the real time clock

// Time and Date

byte sec;
byte min;
byte hour;
byte day;
byte weekday;
byte month;
byte year;
byte century;

//Menu variables i.e. whats in the menu
MenuBackend menu = MenuBackend(menuUsed,menuChanged);

//initialize menuitems
MenuItem menuSetClock = MenuItem("menuSetClock"); // 2nd menu item
MenuItem menuItemHr = MenuItem("menuItemHr"); // sub menu
MenuItem menuItemMin = MenuItem("menuItemMin"); //sub menu
MenuItem menuExit = MenuItem("menuExit"); // 6th menu item



void setup()
{
  lcd.begin(16, 2);
  pinMode(encoderPushButton, INPUT);
  pinMode(buttonPinEsc, INPUT);
  pinMode (encoder0PinA,INPUT);
  pinMode (encoder0PinB,INPUT);



  //How the menu will look.
  lcd.setCursor(0,0);
  menu.getRoot().addRight(menuSetClock); // set main menu items
  menuSetClock.add(menuItemHr).addRight(menuItemMin); // add first sub menu then addright additional sub menues for that menu
  menuExit.add(menuExit);
  menu.toRoot();
} 



void loop()
{
  if (menuRoot == true)
  {
    lcd.setCursor(4, 0);
    lcd.print(rtc.formatTime());
    lcd.setCursor(3, 1);
    lcd.print(rtc.formatDate());

  }
  readButtons(); //I splitted button reading and navigation in two procedures because 
  readEncoder();
  navigateMenus(); //in some situations I want to use the button for other purpose (eg. to change some settings)
  {
  }
} 


void  readButtons() //read buttons status
{  
  int reading;
  int buttonEnterState=LOW; // the current reading from the Enter input pin
  int buttonEscState=LOW; // the current reading from the input pin


  //ENTER BUTTON DEBOUNCE

  reading = digitalRead(encoderPushButton); // read the state of the switch into a local variable:

  if (reading != lastButtonEnterState) // If the switch changed, due to noise or pressing:
  {
    lastEnterDebounceTime = millis(); // reset the debouncing timer
  } 
  if ((millis() - lastEnterDebounceTime) > debounceDelay) // whatever the reading is at, it's been there for longerthan the debounce delay, so take it as the actual current state:
  {         
    buttonEnterState=reading;
    lastEnterDebounceTime=millis();
  }
  lastButtonEnterState = reading; // save the reading.  Next time through the loop, it'll be the lastButtonState:


  //ESC BUTTON DEBOUNCE            

  reading = digitalRead(buttonPinEsc); // read the state of the switch into a local variable:

  if (reading != lastButtonEscState) // If the switch changed, due to noise or pressing:
  {
    lastEscDebounceTime = millis(); // reset the debouncing timer
  } 
  if ((millis() - lastEscDebounceTime) > debounceDelay)// whatever the reading is at, it's been there for longerthan the debounce delay, so take it as the actual current state:
  {
    buttonEscState = reading;
    lastEscDebounceTime=millis();
  }
  lastButtonEscState = reading; // save the reading.  Next time through the loop, it'll be the lastButtonState:

  //Records which button has been pressed
  if (buttonEnterState==HIGH){
    lastButtonPushed=encoderPushButton;
  }
  else if(buttonEscState==HIGH){
    lastButtonPushed=buttonPinEsc;
  }
  else{
    lastButtonPushed=0;
  }                  
}


void readEncoder() //read the encoder and set lastButtonPushed to values used by navigateMenu()
{
  n = digitalRead(encoder0PinA);// n is current state of encoder0PinA pin
  if ((encoder0PinALast == HIGH) && (n == LOW)) // check if encoder0PinA pin has changed state
  {
    if (digitalRead(encoder0PinB) == LOW) 
    {
      lastButtonPushed = 1; //if it has changed and its now low decrement  encoder0Pos;
    } 
    else 
    {
      lastButtonPushed = 2; // if it has changed and its now high, increment encoder0Pos
    }
  } 
  encoder0PinALast = n; // set the variable holding the previous state to the value n read above
}


void menuChanged(MenuChangeEvent changed){

  MenuItem newMenuItem=changed.to; //get the destination menu

  lcd.setCursor(0,0); //set the start position for lcd printing to the second row

  if(newMenuItem.getName()==menu.getRoot()){
    lcd.clear();
    menuRoot = true;    
  }
  //MENU SET CLOCK
  else if(newMenuItem.getName()=="menuSetClock"){
    menuRoot = false;
    lcd.clear();
    lcd.print("Set Clock");
  }
  else if(newMenuItem.getName()=="menuItemHr"){
    lcd.clear();
    lcd.setCursor(0,1);
    lcd.print("Hr");
  }
  else if(newMenuItem.getName()=="menuItemMin"){
    lcd.clear();
    lcd.setCursor(0,1);
    lcd.print("Min");
  }
}


void menuUsed(MenuUseEvent used){ //                  **if you have a function call it here**
  if ( used.item == menuItemHr ){
    lcd.clear();//etc.
    lcd.setCursor(0, 0);
    lcd.print(rtc.formatTime());
    changeHour();
  }
  else if ( used.item == menuItemMin ){
    lcd.clear();//etc.
    lcd.setCursor(0, 0);
    lcd.print(rtc.formatTime());
    changeMin();
  }

  if ( used.item == menuExit ){
    menu.toRoot();//etc.
  }
}


void navigateMenus()
{
  MenuItem currentMenu=menu.getCurrent();

  switch (lastButtonPushed)
  {
  case encoderPushButton: // enter pin
    if(!(currentMenu.moveDown()))//if the current menu has a child and enter has been pressed  then navigate menu to item below
    {  
      menu.use();
    }
    else //otherwise, if menu has no child and enter has been pressed---- the current menu is used
    { 
      menu.moveDown();
    } 
    break;
  case buttonPinEsc:
    lcd.clear();
    menu.toRoot();  //back to main
    break;
  case 1: //Encoder right/buttonPinRight --:
    menu.moveRight();

    break;      
  case 2: //Encoder left/buttonPinLeft ++:
    menu.moveLeft();
    break;      
  }
  lastButtonPushed=0; //reset the lastButtonPushed variable
}


void changeMin(){

  //min=rtc.getMinute();
  if(digitalRead(encoderPushButton) == HIGH)
  {
    min = ++min % 60; //  this is better than // min += 1;as it rolls overfrom 59 to 00
    //if (incrementMinuteButtonPressDectected) min = ++min % 60 // increment and rollover past 59
    //if (decrementMinuteButtonPressDectected) min = (--min + 60) % 60 // decrement and rollunder past 0 
  }
  rtc.setTime(hour, min,sec);
}

void changeHour(){

  // hour=rtc.getHour();

  if(digitalRead(encoderPushButton) == HIGH)
  {
    hour = ++hour % 24; //  this is better than // hour += 1;as it rolls overfrom 59 to 00
    //if (incrementMinuteButtonPressDectected) hour = ++hour % 60 // increment and rollover past 59
    //if (decrementMinuteButtonPressDectected) hour = (--hour + 60) % 60 // decrement and rollunder past 0 
  }
  rtc.setTime(hour, min,sec);
  rtc.setTime(sec, min, hour);
}


void changeDay(){

  // Yet to be done
  if(digitalRead(encoderPushButton) == HIGH)
  {
    day = ++day % 32; //  this is better than // day += 1;as it rolls overfrom 59 to 00
    //if (incrementMinuteButtonPressDectected) dayn = ++day % 31 // increment and rollover past 59
    //if (decrementMinuteButtonPressDectected) day = (--day + 31) % 31 // decrement and rollunder past 0 
  }
  rtc.setDate(day,weekday, month, century, year);
}