#include <Keypad.h>
#include "LiquidCrystal_I2C.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', '#', '.'}
};
int count;
byte rowPins[ROWS] = {5,4,3,2};
byte colPins[COLS] = {11,10,9,8};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
LiquidCrystal_I2C lcd(0x27, 16, 2);
int cursorColumn = 0;
String pad; //variable used to combine key inputs
char key;
void setup() {
Serial.begin(9600);
lcd.init();
lcd.backlight();
keypad.setDebounceTime(10);
}
void loop() {
//Serial.println("Starting menu");
lcd.setCursor(0,0);
lcd.print("Select");
lcd.setCursor(0,1);
lcd.print("A-Out|B-In");
pad = "";
char select = keypad.getKey();
switch(select){
case 'A':
//Serial.println("case");
lcd.clear();
outputMenu();
break;
case 'B':
lcd.clear();
inputMenu();
}
}
void readKey(){//for diesel values
//Serial.println("readkey");
key = keypad.getKey();
Serial.println(key);
if (key != '#' && key != 'A' && key != 'B' && key != 'C'&& key != '*'){
String val = String(key);
pad += val;
}
}
int outputMenu(){
while(1){
readKey();
lcd.setCursor(0,0);
lcd.print("Diesel Amount:");
if (key == '#'){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Saving");
delay(3000);
pad = "";
continue;
}
else if (key == '*'){
lcd.clear();
pad = "";
}
else if (key == 'C'){
lcd.clear();
pad = "";
break;
}
else if (key){
lcd.setCursor(0,1);
lcd.print(pad);
}
}
}
int inputMenu(){
while(1){
readKey();
lcd.setCursor(0,0);
lcd.print("Delivery Amount:");
if (key == '#'){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Saving");
delay(3000);
pad = "";
continue;
}
else if (key == '*'){
lcd.clear();
pad = "";
}
else if (key == 'C'){
lcd.clear();
pad = "";
break;
}
else if (key){
lcd.setCursor(0,1);
lcd.print(pad);
}
}
}