Hi everyone,
I'm currently trying to get my LCD screen to return various info based on certain key presses. So far I have the second if statement working, but the first doesn't seem to be working. The LCD starts by asking "Enter A-D" at (0,0). When the "A" button of the keypad the screen is supposed to clear and then say "Enter Amount 0-255" at the same start. Unfortunately, it doesnt seem to be doing this. I've added lcd.clear() and even tried lcd.begin(16,2) in an attempt to clear it for the message, but nothing seems to work. The second line works if I press "B", so it seems the LCD isnt clearing the top text when it enters the "if" statement.
Is there a way to get the LCD to clear in the "if" statement?
The code is below and also attached for reference. The board I'm using is a mega.
#include <Keypad.h>
#include <Wire.h>
#include <LiquidCrystal.h>
const int rs = 52, en = 11, d4 = 10, d5 = 50, d6 = 12, d7 = 48;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
int out1 = 3;
char keyselect;
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {
9,8,7,6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {
5,4,3,2}; //connect to the column pinouts of the keypad
Keypad customKeypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS); //initialize an instance of class NewKeypad
void setup()
{
lcd.begin(16, 2);
pinMode(out1, OUTPUT);
}
void loop()
{
lcd.setCursor(0,0);
lcd.print("Enter A-D");
keyselect = customKeypad.getKey();
if (keyselect == 'A') {
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Enter Amount 0-255");
}
if (keyselect == 'B') {
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("B Selected");
}
}
V4.ino (1.21 KB)