#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
#include <Wire.h>
LiquidCrystal_I2C lcd(0x27,20,4);
/* Display */
/* Keypad setup */
const byte KEYPAD_ROWS = 4;
const byte KEYPAD_COLS = 4;
byte rowPins[KEYPAD_ROWS] = {12, 11, 10, 9};
byte colPins[KEYPAD_COLS] = {8, 7, 6, 5};
char keys[KEYPAD_ROWS][KEYPAD_COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, KEYPAD_ROWS, KEYPAD_COLS);
uint64_t value = 0;
bool button = 0;
void showSpalshScreen() {
lcd.setCursor(2, 0);
String message = "PasswordSafe";
for (byte i = 0; i < message.length(); i++) {
lcd.print(message[i]);
delay(100);
}
delay(500);
}
void updateCursor() {
if (millis() / 250 % 2 == 0 ) {
lcd.cursor();
} else {
lcd.noCursor();
}
}
void setup() {
Serial.begin(115200);
lcd.init();
lcd.clear();
lcd.backlight();
pinMode(A0, INPUT_PULLUP);
pinMode(A2, OUTPUT);
pinMode(A3, OUTPUT);
showSpalshScreen();
}
String password = "1234";
String passMem = "";
String UnitPrice = "";
unsigned int unitPrice = 15;
char operation = 0;
String memory = "";
String current = "";
uint64_t currentDecimal;
bool decimalPoint = false;
double calculate(char operation, double left, double right) {
switch (operation) {
case '+': return left + right;
case '-': return left - right;
case '*': return left * right;
case '/': return left / right;
}
}
void processInput(char key) {
// if ('-' == key && current == "") {
// current = "-";
// lcd.print("-");
// return;
// }
// switch (key) {
// case '+':
// case '-':
// case '*':
// case '/':
// if (!operation) {
// memory = current;
// current = "";
// }
// operation = key;
// lcd.setCursor(0, 1);
// lcd.print(key);
// lcd.setCursor(current.length() + 1, 1);
// return;
// case '=':
// float leftNum = memory.toDouble();
// float rightNum = current.toDouble();
// memory = String(calculate(operation, leftNum, rightNum));
// current = "";
// lcd.clear();
// lcd.setCursor(1, 0);
// lcd.print(memory);
// lcd.setCursor(0, 1);
// lcd.print(operation);
// return;
// }
// if ('.' == key && current.indexOf('.') >= 0) {
// return;
// }
// if ('.' != key && current == "0") {
// current = String(key);
// } else if (key) {
// current += String(key);
// }
// lcd.print(key);
switch (key) {
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case '0':
lcd.setCursor(0, 1);
passMem = passMem + key;
lcd.setCursor(passMem.length(), 1);
lcd.print(key);
break;
case '=' :
if (passMem == password) {
tone(A5, 500, 1000);
lcd.setCursor(0, 0);
String message = "Unlocking Device";
for (byte i = 0; i < message.length(); i++) {
lcd.print(message[i]);
delay(100);
}
delay(500);
lcd.clear();
} else {
tone(A5, 300, 1000);
lcd.setCursor(0, 0);
String message = "Wrong Password";
for (byte i = 0; i < message.length(); i++) {
lcd.print(message[i]);
delay(100);
}
delay(500);
lcd.clear();
}
break;
}
}
void loop() {
updateCursor();
char key = keypad.getKey();
if (key) {
processInput(key);
}
}