#include <LiquidCrystal.h>
#include <Keypad.h>
// importing the needed librarys
const int rs = 13;
const int en = 12;
const int d4 = 11;
const int d5 = 10;
const int d6 = 9;
const int d7 = 8;
String greeting = "This is a";
String greeting2 = "security panel";
bool start = false;
String username = "";
String password = "";
bool user = true;
bool pass = false;
const uint8_t ROWS = 4;
const uint8_t COLS = 4;
// making a 2 dimension array (for why?)
char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'},
};
struct Pair {
const char* key;
int value;
};
Pair dictionary[] = {
{"ABC", 123},
{"BCD", 456}
};
const int numPairs = sizeof(dictionary) / sizeof(dictionary[0]);
int getValue(const char* key) {
for (int i = 0; i < numPairs; i++) {
if (strcmp(dictionary[i].key, key) == 0) {
return dictionary[i].value;
}
}
return -1;
};
// Setting the pins of the columns and the rows
uint8_t colPins[COLS] = {3, 2, 1, 0};
uint8_t rowPins[ROWS] = {7, 6, 5, 4};
// Absolute no idea what is going on here :D
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
char key = keypad.getKey();
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void functions() {
if (key == keys[3][3]) {
lcd.clear();
lcd.print("Username: ");
lcd.setCursor(9, 0);
}
if (key == keys[3][0] && username.length() == 4) {
lcd.setCursor(0, 1);
lcd.print(("password: "));
lcd.setCursor(9, 1);
user = false;
pass = true;
}
}
void writing() {
if (key != NO_KEY && key != keys[3][3] && key != keys[3][0]) {
lcd.print(key);
if (user) {
username += key;
}
if (pass) {
password += key;
}
}
functions();
if (key == NO_KEY) {
lcd.print("");
}
if (username.length() == 4 && password.length() == 4) {
lcd.clear();
lcd.write("username", "password");
}
}
void setup() {
lcd.begin(16, 2);
lcd.setCursor(3, 0);
for (int i = 0; i < greeting.length(); i++) {
lcd.print(greeting.charAt(i));
delay(100);
}
lcd.setCursor(1, 1);
for (int i = 0; i < greeting2.length(); i++) {
lcd.print(greeting2.charAt(i));
delay(100);
}
delay(1000);
lcd.clear();
lcd.print("Username: ");
lcd.setCursor(9, 0);
}
void loop() {
// Making a char variable and giving it a function output value
writing();
}
/*
struct Pair {
const char* key;
int value;
};
Pair dictionary[] = {
{"piros", 255},
{"zöld", 128},
{"kék", 64}
};
const int numPairs = sizeof(dictionary) / sizeof(dictionary[0]);
int getValue(const char* key) {
for (int i = 0; i < numPairs; i++) {
if (strcmp(dictionary[i].key, key) == 0) {
return dictionary[i].value;
}
}
return -1;
}
void setup() {
Serial.begin(9600);
Serial.println(getValue("piros")); // 255
}
void loop() {}
*/