I have Mega 2560 interfaced with 20x4 LCD and a 4x4 matrix keypad.
My objective is to store an upper limit value and a lower limit value entered from the keypad and use it for comparison with the value that comes from the serial port.(I have made tx and rx connections to max 3232 and rs232, it works fine)
I have written a piece of code which takes input from the keypad and displays it on LCD.
The inputs from the keypad are stored as characters.
I have to implement Back Space operation so that if someone makes a mistake while using the keypad, using back space key they can correct the value, a key should be assigned for back space.
Similarly an Enter operation also have to be realized.
And also how do i reset the board using software?
How can i implement the back space and enter operation?..Please guide me..
#include <Keypad.h>
#include <LiquidCrystal.h>
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] = {30,31,32,33}; //connect to row pinouts
byte colPins[COLS] = {34,35,36,37}; //connect to column pinouts
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
char UL[6];
char LL[6];
int k = 0;
int l = 0;
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup(){
Serial.begin(9600);
// set up the LCD's number of columns and rows:
lcd.begin(20,4);
lcd.cursor();
// set the cursor to column 0, line 0
// (note: line 0 is the first row, since counting begins with 0):
displayMenu();
}
void displayMenu(){
lcd.setCursor(0, 0);
lcd.print("'A'-Enter the Limits");
lcd.setCursor(0, 2);
lcd.print("'B'-Reset");
}
void loop()
{
char key = keypad.getKey();
switch(key) {
case 'A':
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter Upper Limit");
lcd.setCursor(0, 1);
while (k<5){
char key = keypad.getKey();
if (key) {
// Print a message to the LCD.
lcd.print(key);
UL[k] = key;
//Serial.println(key);
k++;
}
}
delay(1000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter Lower Limit");
lcd.setCursor(0, 1);
while(l<5) {
char key = keypad.getKey();
if (key != NO_KEY) {
// Print a message to the LCD.
lcd.print(key);
LL[l] = key;
// Serial.println(key);
l++;
}
}
delay(1000);
lcd.clear();
displayMenu();
break;
case 'B':
break;
case 'C':
break;
case 'D':
break;
//default:
//Serial.println(key);
}
}