Menu Button Selection on LCD screen

Hello,

I am having difficulty developing a program that shows a selection of options on a LCD screen and can be chosen through buttons.

My problem is that on the LCD screen the information keeps scrolling through without stopping. If I push a button it goes to a different screen and prints the correct information but continues to repeat/scroll.

My hardware is as follows:
Rugged Arduino: Ruggeduino-SE "Special Edition" — Rugged CircuitsRugged Arduino
Serial Enabled 20x4 LCD - Black on Green 5V: Serial Enabled 20x4 LCD - Black on Green 5V - LCD-09568 - SparkFun Electronics

I have reduced the code of the switch statement some since essentially all the cases are the same just different options/button pushes.

I have looked at menu selection programs for arduino and they all seem to use switch statements.

My wiring
LCD Rugged Arduino
RX TX
GND GND
VDD +5v

#include <stdlib.h>
#include "mcp_can.h"
#include <SPI.h>
#include "can_ext.h"


int           curr_screen     = 0;
int           prev_screen     = 0;
int           temp_gear_up    = 3;
int           temp_gear_down  = 3;
int           desired_shift_gear_up;
int           desired_shift_gear_down;
bool          auto_shift_type;

char          sString[80];


const String  Blank                 = "                    ";
//buttons
const int     Back                  = 9;
const int     Enter                 = A0;
const int     Reset                 = 2;
const int     Button1               = 3;
const int     Button2               = 4;
const int     Button3               = 5;
const int     Button4               = 6;
const int     Button5               = 12;
//switch statements
const int     main_menu             = 6;
const int     auto_menu             = 7;


unsigned char stmp[8]               = {0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37}; 

// ------------------------------------------------------------------------
//  SYSTEM: Setup routine runs on power-up or reset
// ------------------------------------------------------------------------

// LCD Display Software
void DisplayXY(uint8_t line, uint8_t column)
{
  char A = 0;
  A = 0xFE;
  Serial.print(A);
  A = 0x45;
  Serial.print(A);
  switch(line)
  {
    case 1:  
      A = 0x0;
      break;
    case 2:
      A = 0x40;
      break;
    case 3:
      A = 0x14;
      break;
    case 4:
      A = 0x54;
      break;
    default:
      break;
  }
  A = A + column - 1;
  Serial.print(A);
  delay(2); 
}

// Convert String HEX to Integer
int strhex2int(char *s) 
{
 int x = 0;
 for(;;) {
   char c = *s;
   if (c >= '0' && c <= '9') {
      x *= 16;
      x += c - '0'; 
   }
   else if (c >= 'A' && c <= 'F') {
      x *= 16;
      x += (c - 'A') + 10; 
   }
   else break;
   s++;
 }
 return x;
}


void setup() {

  digitalWrite(Enter      ,INPUT_PULLUP);
  pinMode(Back            ,INPUT_PULLUP);
  pinMode(Button1         ,INPUT_PULLUP);
  pinMode(Button2         ,INPUT_PULLUP);
  pinMode(Button3         ,INPUT_PULLUP);
  pinMode(Button4         ,INPUT_PULLUP);
  pinMode(Button5         ,INPUT_PULLUP);
  pinMode(Reset           ,INPUT_PULLUP);
  
  Serial.begin(9600);
  
}// end setup

// ------------------------------------------------------------------------
// Main Loop - Arduino Entry Point
// ------------------------------------------------------------------------
void loop() 
{
	
	Statedetermination();
 
}// end loop

void Statedetermination()
{
  trans_current_gear = 8;
  ia_lock_state = 1;
  axle_lock_state = 0;
  axle_state = 620;
  vehicle_speed_flag = 1;
  
  //Serial.print("Current_Screen: "); Serial.print(curr_screen); Serial.print("\n\r");
  
      switch (curr_screen) 
      {
       
        case main_menu:
          {  
            DisplayXY(1,1);
            Serial.print("B1: AUTOMATIC       ");
            
            DisplayXY(2,1);
            Serial.print("B2: MANUAL          ");
            
            DisplayXY(3,1);
            Serial.print("B3: DIAGNOSTICS     ");
            
            DisplayXY(4,1);
            Serial.print("Back For Prev Menu  ");
    
            if (digitalRead(Back) == LOW || digitalRead(Reset) == LOW)
            {
              curr_screen = main_menu;
              prev_screen = 0;
            }
            else if (digitalRead(Button1) == LOW)
            {
              curr_screen = auto_menu;
              prev_screen = main_menu;
            }
            else if (digitalRead(Button2) == LOW)
            {
              curr_screen = manual_home;
            }
            else if (digitalRead(Button3) == LOW)
            {
              curr_screen = diagnostics_home;
            }
            
            delay(200);
            break;
          }  
        case auto_menu:
          {  
            while(curr_screen == auto_menu)
            {
                DisplayXY(1,1);
                Serial.print("SELECT STRATEGY     ");
                
                DisplayXY(2,1);
                Serial.print("B1: SINGLE GEAR     ");
                
                DisplayXY(3,1);
                Serial.print("B2: SPLIT GEAR      ");
                
                DisplayXY(4,1);
                Serial.print("Back For Prev Menu  ");
        
                if (digitalRead(Back) == LOW)
                {
                  curr_screen = prev_screen;
                }
                else if (digitalRead(Button1) == LOW)
                {
                  curr_screen = auto_menu_single;
                  auto_shift_type = 0;
                  prev_screen = auto_menu;
                }
                else if (digitalRead(Button2) == LOW)
                {
                  curr_screen = auto_menu_split_up;
                  auto_shift_type = 1;
                  prev_screen = auto_menu;
                }
                else if (digitalRead(Reset) == LOW)
                {
                  curr_screen = main_menu;
                  prev_screen = 0;
                }
            }
            
              delay(200);
	       break;
          }  
         
         default:
          {  
                DisplayXY(1,1);
                Serial.print("B1: AUTOMATIC       ");
                
                DisplayXY(2,1);
                Serial.print("B2: MANUAL          ");
               
                DisplayXY(3,1);
                Serial.print("B3: DIAGNOSTICS     ");
                
                DisplayXY(4,1);
                Serial.print("Back For Prev Menu  ");
        
                if (digitalRead(Back) == LOW || digitalRead(Reset) == LOW)
                {
                  curr_screen = main_menu;
                  prev_screen = 0;
                  
                }
                else if (digitalRead(Button1) == LOW)
                {
                  curr_screen = auto_menu;
                  prev_screen = main_menu;
                  
                }
                else if (digitalRead(Button2) == LOW)
                {
                  curr_screen = manual_home;
                
                }
                else if (digitalRead(Button3) == LOW)
                {
                  curr_screen = diagnostics_home;
                 
                }
      
			          delay(200);
			          break;
		  
          }
    
         
	}
}

}
const String  Blank                 = "                    ";

The WTF light just exploded. There is NO reason to wrap a string in a String instance when the String instance is const.

const int     Button1               = 3;
const int     Button2               = 4;
const int     Button3               = 5;
const int     Button4               = 6;
const int     Button5               = 12;

Do you plan to sew the buttons onto pins in the 10000 to 12000 range later?

These switches serve some purpose. That purpose is NOT 1, 2, 3, 4, and 5. Name the pins for the purpose that the switches serve.

  char A = 0;
  A = 0xFE;

Another WTF moment. Why not just assign A the value 0xFE in the first place?

  digitalWrite(Enter      ,INPUT_PULLUP);

The second argument to digitalWrite() is HIGH or LOW, NOT INPUT_PULLUP.

At that point, Enter is in INPUT mode. Why are you writing to an INPUT pin? Do you know what that accomplishes?

            DisplayXY(1,1);
            Serial.print("B1: AUTOMATIC       ");

To me, it would make a lot more sense if DisplayXY() took three arguments - row, column, and what to display there.

To me, it would make a lot more sense to separate the display of data from the reading of the switches.

        case auto_menu:
          { 
            while(curr_screen == auto_menu)
            {

Why is there a while loop here? Did you forget that loop() loops?

Why are there ANY delays in the code?

I would also think that doing something when a switch BECAME pressed would be more useful than doing something when the switch IS pressed.