#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
#include <Wire.h>
#include <ArduinoJson.h>
// Length of Password +1 for null character
#define Password_Length 4
#define mode_Length 2
//Pin connected to lock relay input
int signalPin = 12;
//Intialize mode number for robot
int mode = 0;
//Character to hold password input
char Input[Password_Length];
//Counter for character entries
byte input_count = 0, master_count = 0;
bool Pass_is_good;
// Chacter to hold key input
char customKey;
const int numRooms = 87;
const int numEngFund = 26;
const int numME_Dept = 21;
const int numCOE_Advisors = 2;
const int numDNE_Rooms = 8;
const int numEXT_Rooms = 3;
//Define rooms in LB
// "182B", "125A", "171A", "173C", 177A
const String allRooms[] = {
"100", "101", "102", "103", "104", "105", "106", "107", "108", "109", "110", "111", "112", "113", "114", "115", "116", "117", "118", "119", "120", "121", "122", "123", "124", "125", "126", "127", "128", "129", "130", "131", "132", "133", "134", "135", "136", "137", "138", "139", "140", "141", "142", "143", "144", "145", "146", "147", "148", "149", "150", "151", "152", "153", "154", "155", "156", "157", "158", "159", "160", "161", "162", "163", "164", "165", "166", "167", "168", "169", "170", "171", "172", "173", "174", "175", "176", "177", "177A", "178", "179", "180", "181", "182", "183", "184", "185", "186"
};
//Engineering Fundemental Department Room Cluster
const String Eng_Fund_Dept[] = {
"100", "101", "102", "103", "104", "105", "106", "107", "108", "109", "110", "111", "112", "113", "114", "115", "116", "117", "118", "119", "120", "121", "122", "123", "124", "125"
};
//Mechanical Engineering Department Room Cluster
const String ME_Dept[] = {
"140", "141", "142", "143", "144", "145", "146", "147", "148", "149", "150", "151", "152", "153", "154", "155", "156", "157", "158", "159", "160"
};
// COE (College of Engineering) Advisor Room Cluster
const String COE_Advisors[] = {
"170","171"
};
//List of Restricted rooms students should not be going to
const String DNE_rooms[] = {
"127", "135", "138", "139", "163", "177", "179", "181"
};
// List of exterior rooms
const String EXT_rooms[] = {
"183","185","186"
};
//Define respones to give user on LCD
char array1[] = "Right this way"; // 14 Characters
char array2[] = "Eng. Fund Dept"; // 14 Characters
char array3[] = "ME Dept"; // CHANGE THIS AS PER YOUR NEED
char array4[] = "COE Advisors"; // CHANGE THIS AS PER YOUR NEED
char array5[] = "Room is restricted"; // CHANGE THIS AS PER YOUR NEED
char array6[] = "That is not a room"; // CHANGE THIS AS PER YOUR NEED
char array7[] = "That room is outside"; // CHANGE THIS AS PER YOUR NEED
char array8[] = "That too long!"; // CHANGE THIS AS PER YOUR NEED
char array9[] = "That too short!"; // CHANGE THIS AS PER YOUR NEED
// Constants for row and column sizes
const byte ROWS = 4;
const byte COLS = 4;
//Array to represent keys on keypad
char hexaKeys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
// Connections to Arduino
byte rowPins[ROWS] = {9, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3, 2};
//Create keypad object
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
//Create LCD object
LiquidCrystal_I2C lcd(0x27, 20, 4);
void setup(){
//Setup LCD with backlight and initialize
lcd.init();
lcd.backlight();
//Set signalPin as an OUTPUT pin
pinMode(signalPin, OUTPUT);
Serial.begin(9600);
}
void loop(){
// Look for Keypress
customKey = customKeypad.getKey();
while (((customKey != 'A') || (customKey != 'B')) && (mode == 0)){
lcd.setCursor(3,0);
lcd.print("Select a mode:");
lcd.setCursor(0,1);
lcd.print("Press A for Tour");
lcd.setCursor(0,2);
lcd.print("Press B for a");
lcd.setCursor(0,3);
lcd.print("specific room");
if (customKey){
if (customKey == 'A'){
mode = 1;
}
else if (customKey == 'B'){
mode = 2;
}
else if ((customKey != 'A') || (customKey != 'B')){
lcd.clear();
lcd.setCursor(3,1);
lcd.print("Not an option"); //13 Characters
delay(1000);
lcd.clear();
}
}
customKey = customKeypad.getKey();
}
if (mode == 1){
lcd.clear();
lcd.setCursor(4,1);
lcd.print("Follow Me!!!"); //12 Characters
delay(2000);
lcd.clear();
mode = 0;
}
else if (mode == 2){
//StaticJsonDocument<200> doc;
//Initialize LCD and print
lcd.clear();
lcd.setCursor(1,0);
lcd.print("Enter 3 digit Room");
lcd.setCursor(6,1);
lcd.print("Number");
lcd.setCursor(2,2);
lcd.print("Press # to Enter");
// Look for Keypress
customKey = customKeypad.getKey();
while (customKey != '#') {
if (customKey){
Input[input_count] = customKey;
lcd.setCursor(input_count,3);
lcd.print(Input[input_count]);
input_count++;
}
customKey = customKeypad.getKey();
}
//String enteredCode = getInput();
//Check if we have reached the password length
if(input_count == Password_Length-1){
delay(1000);
lcd.clear();
// If password is correct
if(isValidRoom(Input)){
if(isValidEngFundRoom(Input)){
lcd.print(array2);
delay(3000);
}
else if(isValidME_DeptRoom(Input)){
lcd.print(array3);
delay(3000);
}
else if(isValidCOE_AdvRoom(Input)){
lcd.print(array4);
delay(3000);
}
else if(isValidDNERoom(Input)){
lcd.print(array5);
delay(3000);
}
else if(isValidEXTRoom(Input)){
lcd.print(array7);
delay(3000);
}
else{
lcd.print(array1);
delay(3000);
}
}
// If password is incorrect
else{
lcd.print(array6);
delay(3000);
}
//Clear LCD after certain time period (Correct or Incorrect)
lcd.clear();
clearData();
mode = 0;
}
else if ((input_count > Password_Length-1)&&(customKey == '#')){
delay(1000);
lcd.clear();
lcd.print(array8);
delay(3000);
//Clear LCD after certain time period (Correct or Incorrect)
lcd.clear();
clearData();
mode = 0;
}
else if ((input_count < Password_Length-1)&&(customKey == '#')){
delay(1000);
lcd.clear();
lcd.print(array9);
delay(3000);
//Clear LCD after certain time period (Correct or Incorrect)
lcd.clear();
clearData();
mode = 0;
}
}
}
bool isValidRoom(String roomCode) {
for (int i = 0; i < numRooms; i++) {
if (roomCode == allRooms[i]) {
return true;
}
}
return false;
}
bool isValidEngFundRoom(String roomFundCode) {
for (int j = 0; j < numEngFund; j++) {
if (roomFundCode == Eng_Fund_Dept[j]) {
return true;
}
}
return false;
}
bool isValidME_DeptRoom(String roomMECode) {
for (int k = 0; k < numME_Dept; k++) {
if (roomMECode == ME_Dept[k]) {
return true;
}
}
return false;
}
bool isValidCOE_AdvRoom(String roomCOECode) {
for (int f = 0; f < numCOE_Advisors; f++) {
if (roomCOECode == COE_Advisors[f]) {
return true;
}
}
return false;
}
bool isValidDNERoom(String roomDNECode) {
for (int d = 0; d < numDNE_Rooms; d++) {
if (roomDNECode == DNE_rooms[d]) {
return true;
}
}
return false;
}
bool isValidEXTRoom(String roomEXTCode) {
for (int d = 0; d < numEXT_Rooms; d++) {
if (roomEXTCode == EXT_rooms[d]) {
return true;
}
}
return false;
}
//Clear data function
void clearData(){
while(input_count !=0){
Input[input_count--] = 0;
}
return;
}
//String getInput() {
// String input = "";
// char key = keypad.getKey();
//
// while (key != '#') {
// if (key) {
// input += key;
// lcd.setCursor(input.length() - 1, 1);
// lcd.print(key); // Display '*' for each key pressed
// }
// key = keypad.getKey();
// }
//
// return input;
//}