Menu issues

Hello!

Can anyone help me out here?

parts using:
1602a lcd
4x4 keypad
arduino r3 (of course)

What I want it to do is boot to a menu screen on startup, then show the available options.

  1. calculator
  2. jump game

You’d press 1 or 2 on the keypad and it goes ahead to the main code corresponding to it.

#include <LiquidCrystal.h> //import lcd library
#include <Keypad.h> //import keypad library

LiquidCrystal lcd(5, 4, 3, 2, 1, 0); //lcd pins
const byte ROWS = 4; // four rows
const byte COLS = 4; // four columns

//define the keymap
char keys [ROWS] [COLS] = {
  {'1', '4', '7', 'X'},
  {'2', '5', '8', '0'},
  {'3', '6', '9', '='},
  {'+', '-', '*', '/'}
};
byte rowPins[ROWS] = {
  9 ,8 ,7 ,6}; //connect keypad ROW1, ROW2, ROW3, ROW4 to these arduino pins
byte colPins[COLS] = {
  13, 12, 11, 10}; //connect keypad COL1, COL2, COL3, COL4 to these arduino pins

//create the keypad
Keypad myKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

//variables declaration
boolean valOnePresent = false;
boolean next = false;
boolean final = false;
String num1, num2;
int ans;
char op;
int mode;
int start;

void setup(){

  
}


void loop(){
  char key = myKeypad.getKey();
  mode = 0;
  start = 0;
  lcd.begin(16,2);
  // This is the code that picks a certain mode
  // It will keep looping until a valid mode is set
 while(mode == 0){
  if (start == 0){
  lcd.setCursor (0,0);
  lcd.print("Welcome to");
  lcd.setCursor (2,1);
  lcd.print("ArdCalc");}
  delay(800);
  lcd.clear();
  start = 1;
  lcd.print ("1) Calculator");
  lcd.setCursor (0,1);
  lcd.print (mode);
    if (key != NO_KEY && (key=='1'||key=='2')) {
      mode = mode + key;
    }
    delay(800);
  }
  // End setup mode
  
  if (mode == 1){
    //rest of calculator code

I don’t get any errors compiling, but when i push 1, nothing happens. it should run the calculator code, but it stays put at the menu.

I know for a fact the keypad works, by the way.

thanks in advance. Don’t hesitate to ask questions!

if (key != NO_KEY && (key=='1'||key=='2')) {
      mode = mode + key;

You do know that 0 + '1' == 49 right?

1 is the number 1

'1' is the ascii code for a 1 character which is the number 49.

If you look at the ascii table, you'll see that it's dead easy to convert a single digit from ascii to a real number by just subtracting 48 (also written as '0').

Set you menu items in the setup and keep the variable count that corresponds to the actions such as 1 and 2 set at 0 from the start.

The lcd will set the cursor and print what you describe you want and then until you have input from the key pad the menu will stay like that being the count is 0. When user inputs 1 or 2 it changes to corresponding code.