Creating a menu for 16x2 LCD keypad shield

Hi

I am trying to create a simple menu for my LCD (as a way of learning how to use it), my basic approach is to have two buttons, one that adds 1 and one that subtracts 1 from the total value, and depending on the what the total value is, display a menu option. For example, if the total value is 1 it will display “menu option 1” and so on, then when the menu option is selected it will trigger an action like an LED flashing on and off.

The problem that I have at the moment is that the displayed “menu option 1” and “menu option 2” are on top of each other causing the 1 and 2 to flicker between each, how do I solve this?

//Testing the use of addition and subtraction with the menu options.

#include <LiquidCrystal.h>

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);         


int lcd_key     = 0;
int adc_key_in  = 0;
int calc_total;
int display_options;

#define btnRIGHT  0
#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3
#define btnSELECT 4
#define btnNONE   5

int read_LCD_buttons(){              
    adc_key_in = analogRead(0);     

  

    if (adc_key_in > 1000) return btnNONE; 


    if (adc_key_in < 50)   return btnRIGHT;  
    if (adc_key_in < 150)  return btnUP; 
    if (adc_key_in < 300)  return btnDOWN; 
    if (adc_key_in < 450)  return btnLEFT; 
    if (adc_key_in < 700)  return btnSELECT;  

  

    return btnNONE;      
    
}

void setup(){
   lcd.begin(16, 2);              
   lcd.setCursor(0,0);    
   lcd.print (calc_total);  
       
}
 
void loop(){
   
   lcd_key = read_LCD_buttons();  
   

   switch (lcd_key){              
    
       case btnRIGHT:{  
            lcd.clear();
            lcd.setCursor(0,1); 
            calc_total = calc_total - 1;
            calc_total = constrain(calc_total,-5, 5);
            lcd.print(calc_total);
            delay(700); 
            break;
       }
       case btnLEFT:{
            lcd.clear();
            lcd.setCursor(0,1);
            calc_total = calc_total + 1;
            calc_total = constrain(calc_total,-5, 5);
            lcd.print (calc_total);
            delay(700);
            break;
       }
     }
     
    if (calc_total = 1){
      //lcd.clear();
      lcd.setCursor(0,0); 
      lcd.print("Menu Option 1");
    }
    if (calc_total = 2){
      //lcd.clear();
      lcd.setCursor(0,0); 
      lcd.print("Menu Option 2");
    }
    
}

PErhaps you need to change this code:

if (calc_total = 1){ //lcd.clear(); lcd.setCursor(0,0); lcd.print("Menu Option 1"); } if (calc_total = 2){ //lcd.clear(); lcd.setCursor(0,0); lcd.print("Menu Option 2"); }

to be:

if (calc_total == 1){ //lcd.clear(); lcd.setCursor(0,0); lcd.print("Menu Option 1"); } if (calc_total == 2){ //lcd.clear(); lcd.setCursor(0,0); lcd.print("Menu Option 2"); }

See the difference?

Paul

ahhh the = should be ==, thank you

Liam