So I have set up a keypad and an LCD screen. What I want to do is prompt the user to set some values that I will use later in the program. I have the LCD and the keypad set up, but I am having trouble having the users button presses appear on the screen where I want them (the clear function does not seem to be working for some reason) and I cannot figure out how to take there inputs and set them to a variable.
Here is what I have currently
#include <LiquidCrystal.h>
#include <Keypad.h>
float userset = 0;
LiquidCrystal lcd(24, 22, 32, 30 ,28, 26);
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'S','0','P','D'}
};
byte rowPins[ROWS] = {23,25,27,29};
byte colPins[COLS] = {31,33,35,37};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup()
{
Serial.begin(9600);
lcd.begin(16,2);
lcd.setCursor(2,0);
lcd.print("Brew Perfect");
lcd.setCursor(2,1);
lcd.print("Mandel Tech");
delay(4000);
keypad.setDebounceTime(20);
}
void initLCDKeys()
{
for (int i = 0; i < sizeof(rowPins); i++)
pinMode(rowPins[i],OUTPUT);
for (int i = 0; i < sizeof(colPins); i++)
{
pinMode(colPins[i],INPUT);
digitalWrite(colPins[i],LOW);
}
}
void loop()
{
lcd.clear();
char key = keypad.getKey();
initLCDKeys();
delay(20);
if (key != NO_KEY){
Serial.println(key);
if (key == 'A')
{
lcd.setCursor(2,1);
lcd.write(" ");
lcd.setCursor(2,1);
}
if (key == 'D')
{
userset = 0; // Need to set to what user has entered
} else
lcd.print(key);
}
lcd.setCursor(2, 0);
lcd.print("Set Timer");
lcd.setCursor(0, 1);
lcd.print("Press F1 to Comp");
delay(2000);
lcd.clear();
lcd.setCursor(2, 1);
lcd.print(key);
lcd.setCursor(2, 0);
lcd.print("Thanks");
}
What I would like is as they type it appears on the screen so they can check for accuracy. Pressing A would be a clear function, and D would be submit. I think the code should mostly do that but it is not quite working. Also I cannot figure out how to connect there input with the variable I have defined as "userset" (this is where the code is commented).
Thanks for the help, I am learning as quickly as I can but there is a lot to take in.