Multiple options with one keypad

Dear all

I am trying to write a code to return number from the keypad, and then make two options as sequence below

1- When the program starts, Enter number and press #
2- Return number,

3-for option one, press A,
4-for option two press B,

I wrote the code for steps 1 and 2 but stuck with 3 and 4.

my code;

#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd1(0x26, 20, 4);



long num=0;


//Define OutPuts ports

const int V1=22;
const int V2=23;


// Set 4x4 Keypad
const byte ROWS = 4;
const byte COLS = 4;
char txt1[] = "Press Start";
char hexaKeys[ROWS][COLS] = {
                            {'1', '2', '3', 'A'},
                            {'4', '5', '6', 'B'},
                            {'7', '8', '9', 'C'},
                            {'*', '0', '#', 'D'}
                            };

byte rowPins[ROWS] = {46, 47, 48, 49};
byte colPins[COLS] = {50, 51, 52, 53};

Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

char entryStr[12];   // This can hold up to 4 digits





void setup() {


  
  pinMode(V1, OUTPUT);
  pinMode(V2, OUTPUT);
  
}


  
void loop() {

  while(1) {


    lcd1.clear();
    lcd1.setCursor(0, 0);
    lcd1.print("Input");
    delay(500);
    lcd1.clear();
    lcd1.print("Filtration Volume");
    delay(500);
    lcd1.clear();
   byte n1 ;
  //_________ setting Keypad logic -----------

    lcd1.setCursor(0, 0);
    lcd1.print("number of l ?");
    lcd1.setCursor(0, 1);
    lcd1.print("and press #");
 unsigned char state;
      long num = 0;
      char hexaKeys = customKeypad.getKey();

      while (hexaKeys != '#')
      {
        switch (hexaKeys)
        {
          case NO_KEY:
            break;
          case 'D': case '2': case '3': case 'A':
          case '4': case '5': case '6': case 'B':
          case '7': case '8': case '9': case 'C':
          case '0': case '1':

            lcd1.print(hexaKeys);
            num = num * 10 + (hexaKeys - '0');
            break;

          case '*':
            num = 0;
            lcd1.clear();
            lcd1.setCursor(0, 0);
            lcd1.print("number of l ?");
            lcd1.setCursor(0, 1);
            lcd1.print("and press #");

            break;

          case '#':
            return num;
            
            break;

        }

        hexaKeys = customKeypad.getKey();

      }

       

   
     } }

Now I need your support to add another option like

if hexaKeys = 1 gotot option A
if hxakeys = 2 goto option B

You don't need the while(1) loop. That is what the function loop() is for. Where are you returning to in the following case statement?

        case '#':
          return num;
          break;

As it turns out that case statement will never get executed anyhow.

I can't figure out what you are asking for. The following seem to contradict:

HayderIsmael:
3-for option one, press A,
4-for option two press B,

if hexaKeys = 1 gotot option A
if hxakeys = 2 goto option B

Thank you for your replay,

I meant after entering a number, the program will return it and store it,to compare later in a condition, then I will have to press again either, for example, number '1' or '2' to go an implement different options, for example,

if I press '1', LED1 ON
if I press '2', LED2 ON

Here is your code properly formatted with the while(1) removed:

#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd1(0x26, 20, 4);

long num = 0;

//Define OutPuts ports
const int V1 = 22;
const int V2 = 23;

// Set 4x4 Keypad
const byte ROWS = 4;
const byte COLS = 4;
char txt1[] = "Press Start";
char hexaKeys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};

byte rowPins[ROWS] = {46, 47, 48, 49};
byte colPins[COLS] = {50, 51, 52, 53};

Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

char entryStr[12];   // This can hold up to 4 digits

void setup() {
  pinMode(V1, OUTPUT);
  pinMode(V2, OUTPUT);
}

void loop() {
  lcd1.clear();
  lcd1.setCursor(0, 0);
  lcd1.print("Input");
  delay(500);
  lcd1.clear();
  lcd1.print("Filtration Volume");
  delay(500);
  lcd1.clear();
  byte n1 ;
  //_________ setting Keypad logic -----------

  lcd1.setCursor(0, 0);
  lcd1.print("number of l ?");
  lcd1.setCursor(0, 1);
  lcd1.print("and press #");
  unsigned char state;
  long num = 0;
  char hexaKeys = customKeypad.getKey();

  while (hexaKeys != '#')
  {
    switch (hexaKeys)
    {
      case NO_KEY:
        break;

      case 'D': case '2': case '3': case 'A':
      case '4': case '5': case '6': case 'B':
      case '7': case '8': case '9': case 'C':
      case '0': case '1':
        lcd1.print(hexaKeys);
        num = num * 10 + (hexaKeys - '0');
        break;

      case '*':
        num = 0;
        lcd1.clear();
        lcd1.setCursor(0, 0);
        lcd1.print("number of l ?");
        lcd1.setCursor(0, 1);
        lcd1.print("and press #");
        break;

      case '#':
        return num;  // !!!!!!!! This doesn't return anywhere!!!
        break;
    }

    hexaKeys = customKeypad.getKey();
  } // end while
}

The return in your case ‘#’: case returns num. What do you really want it to do? loop() is a void function so you shouldn’t return anything and in most cases it makes no sense to return from loop.

Also, what do you intend your case ‘*’: case to do? Is that where you intended to enter 1 or 2 for the LEDs?

Thank you for your replay.

This is apart of long code running multi actuators, case'*' is to clear data and re-enter num. Case '#' to store num which I will compare it with a counter to stop some operation. What I need to do is, after return num by pressing # I got new entry options using the same keypad as well.

scenario:

1-Start
2-Enter the number of l and press # (now num is stored for later)
3- (New menu) select option 1 or 2
4- press 1, then option 1
5-press 2, then option 2.

thank you

Here is a flow chart of what I am trying to do, please help,

OP image:

oh guys, so sorry,

I have checked my code many times and lastly found the problem from the Arduino board itself. I replaced it and my code with multi-options works perfectly