#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
LiquidCrystal_I2C screen(0x27, 16, 2);
// Keypad info
const byte cols = 4, rows = 4;
char keys[rows][cols] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowpins[4] = {9, 8, 7, 6}, colpins[4] = {5, 4, 3, 2};
Keypad inputkeypad = Keypad(makeKeymap(keys), rowpins, colpins, rows, cols);
// Price info
double total = 0;
// Input
String priceinput = "";
byte mode = 0;
void setup() {
screen.init();
screen.backlight();
Serial.begin(9600);
}
void loop() {
screen.clear();
char inputkey = inputkeypad.getKey();
if (inputkey) {
if (inputkey == 'C') {mode = 2; screen.clear();}
if (inputkey == 'D') {priceinput += ".";}
else if (inputkey == '*') {
switch (mode) {
case 1: total += priceinput.toDouble(); priceinput = ""; mode = 0;
case 2: total = 0; mode = 0;
}
}
else if (inputkey == '#') {
if (mode == 1) {priceinput = "";}
}
else if (! (inputkey == 'A' || inputkey == 'B')) {mode = 1; priceinput += inputkey;}
}
switch (mode) {
case 0:
screen.home();
screen.print("Type item price");
screen.setCursor(0, 1);
screen.print(String("Total: P") + String(total));
case 1:
screen.print(priceinput);
screen.setCursor(0, 1);
screen.print("*:Entr #:Cancl");
case 2:
screen.print("Do you wanna");
screen.setCursor(0,1);
screen.print("start over?");
delay(1000);
screen.home();
screen.print("*:Yes #:No");
}
delay(100);
}