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();
}
}