Trouble with sub menu system-4x4 keypad and 1602 LCD

Greetings!

I am trying to implement a menu system, interfacing 4x4 keypad and 1602 LCD with arduino UNO board. In the code, I want to present user with two options to enter, either seconds or minutes. Upon selection, I would further want the user to enter the time value for which a certain operation is performed(in this case its lighting up LED at pin 13 for that duration).
However, I am facing some errors in getting the output right. First, the menu selection screen looks like its just printing the selections indefinitely(pic attached) and doesnt accept anything “A” or “B”. Secondly, even if I reform the code to select one value, the second getkey() function doesnt work properly.

Can anyone please help me out with this? I would be extremely grateful.

#include<string.h>
#include <Keypad.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 10, 11, 12, 13);
char keys[4][4] = { //declare an array
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};
byte rowPins[4] = {7, 6, 5, 4};
byte colPins[4] = {3, 2, 1, 0};
//initialize an instance of class Keypad
Keypad mykeypad = Keypad(makeKeymap(keys), rowPins, colPins, 4, 4);
int myInt = 0;
void setup()
 {

  lcd.begin(16,2);
  lcd.clear();
}
void loop() {
  char key = mykeypad.getKey() ;

lcd.print("A. Seconds");
lcd.setCursor(0,1);
lcd.print("B. Minutes");
if (key == 'A')
{
  lcd.print("seconds: ");
  seconds();
}
else if (key == 'B')
{
  lcd.print("minutes:");
  minutes();
}
}
void seconds()
{ int j=0;
  lcd.setCursor(0,1);
  while(j!=4)
  {
    char key1=mykeypad.getKey();
    lcd.leftToRight();
    lcd.print(key1);
    myInt = (myInt * 10) + key1 -'0';
    j++;
  }
  digitalWrite(13,HIGH);
  delay(myInt*1000);
  digitalWrite(13,HIGH);  
  lcd.clear();

}
void minutes(char type)

{ int j=0;
  lcd.setCursor(0,1);
  while(j!=4)
  {
    char key1=mykeypad.getKey();
    lcd.leftToRight();
    lcd.print(key1);
    myInt = (myInt * 10) + key1 -'0';
    j++;
  }
  digitalWrite(13,HIGH);
  delay(myInt*60000);
  digitalWrite(13,HIGH);  
  lcd.clear();
 }
}

Maybe slow down a bit and see if a key has been pressed.

Ok. Nothing happens when I press either 'A' or 'B'. It does not go down to the if/else clause.

Most of the time, you won’t have any keys pressed, but you’ll have a lot of flicker.
You could fix that.
What do your debug prints tell you?

I am sorry but I am not aware of any debug prints in the sketch application for Arduino. Can you please guide me step by step what to look for? and where to begin with debugging?

For starters, I have commented out all the subsequent code and focused on the first print command in void loop(). In the display, it is looping “A. Seconds” endlessly(image attached). I may be missing out something very basic here but my brain is fried from working on this since 24 hours.

#include<string.h>
#include <Keypad.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 10, 11, 12, 13);
char keys[4][4] = { //declare an array
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};
byte rowPins[4] = {7, 6, 5, 4};
byte colPins[4] = {3, 2, 1, 0};
Keypad mykeypad = Keypad(makeKeymap(keys), rowPins, colPins, 4, 4);
int myInt = 0;
void setup()
 {

  lcd.begin(16,2);
  lcd.clear();
}
void loop() {
  char key = mykeypad.getKey() ;

lcd.print("A. Seconds");
//lcd.setCursor(0,1);
//lcd.print("B. Minutes");
//if (key == 'A')
//{
//  lcd.print("seconds: ");
//  seconds();
//}
//else if (key == 'B')
//{
//  lcd.print("minutes:");
//  minutes();
//}
//}
//void seconds()
//{ int j=0;
//  lcd.setCursor(0,1);
//  while(j!=4)
//  {
//    char key1=mykeypad.getKey();
//    lcd.leftToRight();
//    lcd.print(key1);
//    myInt = (myInt * 10) + key1 -'0';
//    j++;
//  }
//  digitalWrite(13,HIGH);
//  delay(myInt*1000);
//  digitalWrite(13,HIGH);  
//  lcd.clear();
//
//}
//void minutes(char type)
//
//{ int j=0;
//  lcd.setCursor(0,1);
//  while(j!=4)
//  {
//    char key1=mykeypad.getKey();
//    lcd.leftToRight();
//    lcd.print(key1);
//    myInt = (myInt * 10) + key1 -'0';
//    j++;
//  }
//  digitalWrite(13,HIGH);
//  delay(myInt*60000);
//  digitalWrite(13,HIGH);  
//  lcd.clear();
// }
}

You are going to get ‘supreme hell’ for working on that crocheted doily !

lcd.setCursor(0,1);

//                   111111
//         0123456789012345         
lcd.print("A. Seconds      ");

Thanks larryd, that was indeed helpful.
TheMemberFormerlyKnownAsAWOL, I am finally able to debug the whole code and sort it out. Introduced flags and checked the state of the code at each level. Thanks for the input.

One full day of coding and juggling multiple things at home during WFH messed up the logic a bit. A good night of sleep was all I needed :slight_smile:

This thread ends here