Security System
Dependencies: mbed ID12RFID TextLCD keypad
Revision 2:bcdd700feee0, committed 2021-12-04
- Comitter:
- mabelliard
- Date:
- Sat Dec 04 10:13:46 2021 +0000
- Parent:
- 1:43e6a97f7d4d
- Commit message:
- Final Copy;
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 43e6a97f7d4d -r bcdd700feee0 main.cpp --- a/main.cpp Sun Nov 28 23:21:59 2021 +0000 +++ b/main.cpp Sat Dec 04 10:13:46 2021 +0000 @@ -1,16 +1,17 @@ -#include "mbed.h" -#include "TextLCD.h" -#include "ID12RFID.h" -#include "Keypad.h" -#include "emic2.h" +#include "mbed.h" //MBED library +#include "TextLCD.h" //LCD library +#include "ID12RFID.h" //RFID library +#include "Keypad.h" //Keypad library +#include "emic2.h" //Speech library emic2 myTTS(p13, p14); //serial RX,TX pins to emic -Serial pc(USBTX, USBRX); -ID12RFID rfid(p27); // uart rx -TextLCD lcd(p15, p16, p21, p22, p23, p24); //rs,e,d0,d1,d2,d3 -DigitalIn PhysicalKey(p5); -Keypad keypad(p7, p12, p11, p9, p8, p6, p10, NC); +Serial pc(USBTX, USBRX); // Self Explanatory +ID12RFID rfid(p27); // uart rx +TextLCD lcd(p15, p16, p21, p22, p23, p24); //rs,e,d0,d1,d2,d3, Digital Out Pins +DigitalIn PhysicalKey(p5); //Digital In pin +Keypad keypad(p7, p12, p11, p9, p8, p6, p10, NC); //Digital out and Digital in Pins for Keypad +DigitalOut Box[2]={p29, p30}; //LED ligts to show what door opens at the end // Define your own keypad values char Keytable[] = {'1', '2', '3', // r0 @@ -18,127 +19,137 @@ '7', '8', '9', // r2 '*', '0', '#'}; // r3 // c0 c1 c2 - -uint32_t Password[4]={1, 2, 3, 4}; -uint32_t PasswordTry[4]; -uint32_t Index; + +uint32_t Password[4]={1, 2, 3, 4}; //General Password is 1234 +uint32_t PasswordTry[4]; //Where your password attempt is stored +uint32_t Index; //keypad library output from 0 to 11 defined as + /* + {'0', '1', '2', // r0 + '3', '4', '5', // r1 + '6', '7', '8', // r2 + '9', '10', '11'}; // r3 + // c0 c1 c2 + */ uint32_t cbAfterInput(uint32_t index) { - Index = index; + Index = index; //the actual output of the library is index, we assign it to Index return 0; } //Entry Verification Levels DigitalOut CardAuthorized(LED1); //Authorized Card Notification DigitalOut PinAuthorized(LED2); //Authorized Pin Notification -DigitalOut QuestionAuthorized(LED3); //Approved Secuirty Question +DigitalOut QuestionAuthorized(LED3); //Approved Security Question DigitalOut DoorUnlock(LED4); //Approved Entry //Stored integers to manipulate security information int Attempts = 0; //Counts how many times Timer ResetEvertyhing has been triggered, and failures int CardDATA; //initializes the rfid.read() function early so theres no delay to display the Data -int Z; -int UserIdentifier = 0; -int CorrectNumbersCounter = 0; -int CorrectNumbersCounter1 = 0; -int SongCounter = 0; -int Card[10]={22352713, 22374742}; -int SongEE[4]= {12, 12, 12, 12}; -int CorrectCard = 0; -char Question[2][64]= {"What is your social security number", - "How many dicks can fit in your ass"}; -uint32_t QuestionAnswers[2][4]={ {5, 5, 5, 5}, - {6, 6, 6, 6} }; -void ResetLocks(void); +int UserIdentifier = 0; //Self Explanatory +int CorrectNumbersCounter = 0; //Used to count how many inputs of the keypad were correct in Pin section +int CorrectNumbersCounter1 = 0; //Used to count how many inputs of the keypad were correct in Question section +int SongCounter = 0; //Used to count how many correct inputs was entered to initiat the song easter egg +int Card[10]={22352713, 22374742}; //Stored value of RFID Cards +int SongEE[4]= {12, 12, 12, 12}; //Stored value for keypad input to start the song easter egg #### +int CorrectCard = 0; // +char Question[2][64]= {"What is your social security number", //Self Explanatory + "How many pets do you own"}; +char UserNames[2][10]= {"Marco", //Self Explanatory + "Chris"}; + +uint32_t QuestionAnswers[2][4]={ {5, 5, 5, 5}, //unint32_t is used because keypad library uses it + {11, 11, 11, 1} }; //and we need to compare the password to keypad entries + //0, 0, 0, 0 + +void ResetLocks(void); //resets the locks void ResetLocks(void){ - CardAuthorized = 0; - PinAuthorized = 0; - QuestionAuthorized = 0; - DoorUnlock = 0; - CorrectCard = 0; - CorrectNumbersCounter = 0; - CorrectNumbersCounter1 = 0; - UserIdentifier = 0; - SongCounter = 0; + CardAuthorized = 0; // Reset Card + PinAuthorized = 0; // Reset Pin + QuestionAuthorized = 0; //Reset Question Asked Section + DoorUnlock = 0; //Locks the Door + CorrectCard = 0; //Resets if a correct card has been detected + CorrectNumbersCounter = 0; //Resets whether Pin entered matches Pin Answer + CorrectNumbersCounter1 = 0;//Resets whether Pin entered mathes Question Answer + UserIdentifier = 0; //Identfies the User, default being 0, aka Marco + SongCounter = 0; //Resets the easter egg + Box[0]=0; //Closes the Door 0 for Marco + Box[1]=0; //Closes the Door 1 for Chris } + int main(){ - myTTS.volume(18); //max volume + myTTS.volume(18); //max volume keypad.attach(&cbAfterInput); keypad.start(); // energize the keypad via c0-c3 - int run_once1 = 0; - int run_once2 = 0; - int run_once3 = 0; - myTTS.voice(2); - while(1){ + int run_once1 = 0; //neccesary to run a statement once in a while loop + int run_once2 = 0; //neccesary to run a statement once in a while loop + int run_once3 = 0; //neccesary to run a statement once in a while loop + myTTS.voice(2); //sets the voice profile of the speech module + + while(1){ //where the program mainly runs continuously while(PhysicalKey == 0) { //key either not inserted and/or turned - if (run_once1 == 0){ - ResetLocks(); - lcd.cls(); - pc.printf("Please Insert Physical Key\n\r"); - lcd.printf("Please Insert Physical Key \n"); - myTTS.speakf("S");//Speak command starts with "S" - myTTS.speakf("Please Insert Physical Key"); // Send the desired string to convert to speech - myTTS.speakf("\r"); //marks end of speak command - myTTS.ready(); //ready waits for speech to finish from last command with a ":" response + if (run_once1 == 0){ //run the function below once to avoid spam + ResetLocks(); //When key isnt inserted, lock everything + lcd.cls(); //clear screen + pc.printf("Please Insert Physical Key\n\r"); //Terminal Print + lcd.printf("Please Insert Physical Key \n"); //LCD Print + myTTS.speakf("S Please Insert Physical Key \r"); //S starts speech for desired string, \r ends speech + myTTS.ready(); //ready waits for speech to finish from last command run_once1 = 1; } } while(PhysicalKey == 1) { //key inserted and turned run_once1 = 0; if (run_once2 == 0){ - lcd.cls(); - pc.printf("Please Scan Card\n\r"); + lcd.cls(); // + pc.printf("Please Scan Card\n\r"); // lcd.printf("Please Scan Card \n"); - myTTS.speakf("S");//Speak command starts with "S" - myTTS.speakf("Please Scan Card"); // Send the desired string to convert to speech - myTTS.speakf("\r"); //marks end of speak command - myTTS.ready(); //ready waits for speech to finish from last command with a ":" response + myTTS.speakf("S Please Scan Card \r"); + myTTS.ready(); run_once2 = 1; } - else if (Attempts > 3) { + else if (Attempts > 3) { //if you fail any step more than 3 times, this function startys lcd.cls(); pc.printf("Too many Attempts\n\r"); lcd.printf("Too many Attempts\n"); - myTTS.speakf("S");//Speak command starts with "S" - myTTS.speakf("Too many Attempts"); // Send the desired string to convert to speech - myTTS.speakf("\r"); //marks end of speak command - myTTS.ready(); //ready waits for speech to finish from last command with a ":" response + myTTS.speakf("S Too many Attempts \r"); + myTTS.ready(); lcd.cls(); pc.printf("LOCKED for 30 Minutes\n\r"); lcd.printf("LOCKED for 30 Minutes\n"); - myTTS.speakf("S");//Speak command starts with "S" - myTTS.speakf("Locked for 30 Minutes"); // Send the desired string to convert to speech - myTTS.speakf("\r"); //marks end of speak command - myTTS.ready(); //ready waits for speech to finish from last command with a ":" response + myTTS.speakf("S Locked for 30 Minutes \r"); + myTTS.ready(); - wait(1800); - + for(int LockedOut = 30; LockedOut>0; LockedOut--){ //Lockout Timer + lcd.cls(); + lcd.printf("Time Remaining:"); + lcd.printf("\n%d Minutes", LockedOut); + wait(60); + } Attempts = 0; } - else if((rfid.readable())&&(Attempts < 4)) { + + else if((rfid.readable())&&(Attempts < 4)) { //if the RFID Reader has a Value stored and attempts less than 4 lcd.cls(); CardDATA = rfid.read(); pc.printf("RFID Tag Number:%d\n\r",CardDATA); lcd.printf("RFID Tag Number:%d\n",CardDATA); wait(1); - for(Z = 0; Z<100; Z++){ + for(int Z = 0; Z<100; Z++){ if(CardDATA==Card[Z]){ - UserIdentifier = Z; - CorrectCard = CorrectCard + 1; - //pc.printf("Counter :%d\r\n", CorrectNumbersCounter); + UserIdentifier = Z; //Whatever Z is when the correct card is Scan is the User + CorrectCard = CorrectCard + 1; //+1 on counter if anything from CARD[Z] = card read } } - if(CorrectCard == 0){ + if(CorrectCard == 0){ //enter this function if the wrong card was read lcd.cls(); - lcd.printf("Fuck You\n"); - pc.printf("Fuck You\n\r"); - myTTS.speakf("S");//Speak command starts with "S" - myTTS.speakf("Fuck You"); // Send the desired string to convert to speech - myTTS.speakf("\r"); //marks end of speak command - myTTS.ready(); //ready waits for speech to finish from last command with a ":" response + lcd.printf("Incorrect\n"); + pc.printf("Try Again\n\r"); + myTTS.speakf("S Try Again \r"); + myTTS.ready(); + Attempts = Attempts + 1; wait(2); } - else if(CorrectCard == 1){ + else if(CorrectCard == 1){ //enter this function if the right card was read CorrectCard = 0; lcd.cls(); lcd.printf("Card Accepted\n"); @@ -151,28 +162,26 @@ lcd.cls(); lcd.printf("Type Pin: "); pc.printf("Type Pin: "); - myTTS.speakf("S");//Speak command starts with "S" - myTTS.speakf("Type Common Pin"); // Send the desired string to convert to speech - myTTS.speakf("\r"); //marks end of speak command - myTTS.ready(); //ready waits for speech to finish from last command with a ":" response + myTTS.speakf("S Type Common Pin \r"); + myTTS.ready(); for(int A=0; A<4; A++){ __wfi(); - PasswordTry[A]= Index + 1; - lcd.printf("%c", Keytable[Index]); + PasswordTry[A]= Index + 1; //Index +1 because index is 0 to 11, instead of 1 to 12 + lcd.printf("%c", Keytable[Index]); //prints keytable pc.printf("%c", Keytable[Index]); - wait(0.3); + wait(0.2); } for(int B=0; B<4; B++){ if(PasswordTry[B]==Password[B]){ - CorrectNumbersCounter = CorrectNumbersCounter + 1; + CorrectNumbersCounter = CorrectNumbersCounter + 1; //counts how many times Each array equal each other } } - for(int Song=0; Song<4; Song++){ + for(int Song=0; Song<4; Song++){ //checks if the song array is equal to password try array if(PasswordTry[Song]==SongEE[Song]){ SongCounter = SongCounter + 1; } } - if(SongCounter == 4){ + if(SongCounter == 4){ //plays song lcd.cls(); lcd.printf("Easter Egg ON\n"); pc.printf("\n\rEaster Egg ON\n\r"); @@ -180,7 +189,7 @@ myTTS.ready(); //member function wait SongCounter = 0; } - else if(CorrectNumbersCounter == 4){ + else if(CorrectNumbersCounter == 4){ //Continues program if pin is correct SongCounter = 0; lcd.cls(); lcd.printf("Pin Accepted\n"); @@ -189,142 +198,130 @@ PinAuthorized = 1; Attempts = 0; } - else if (CorrectNumbersCounter < 4){ + else if (CorrectNumbersCounter < 4){//if pin is incorrect, adds 1 attempt SongCounter= 0; CorrectNumbersCounter = 0; lcd.cls(); lcd.printf("FAIL"); pc.printf("FAIL"); - myTTS.speakf("S");//Speak command starts with "S" - myTTS.speakf("Incorrect Entry"); // Send the desired string to convert to speech - myTTS.speakf("\r"); //marks end of speak command - myTTS.ready(); //ready waits for speech to finish from last command with a ":" response + myTTS.speakf("S Incorrect Entry \r"); + myTTS.ready(); Attempts = Attempts + 1; if(Attempts == 4){ ResetLocks(); } } - while ((PinAuthorized == 1)&&(PhysicalKey == 1)) { - //security question + while ((PinAuthorized == 1)&&(PhysicalKey == 1)) { //if the pin turned on Pinauthorized earlier enter funtion + //security question section, Everything in this section is identical to the previous section, except for the question part lcd.cls(); lcd.printf("Security\n"); lcd.printf("Question\n"); pc.printf("Security Question\n\r"); - myTTS.speakf("S");//Speak command starts with "S" - myTTS.speakf("Security Question"); // Send the desired string to convert to speech + myTTS.speakf("S Security Question \r"); myTTS.speakf("\r"); //marks end of speak command - myTTS.ready(); //ready waits for speech to finish from last command with a ":" response + myTTS.ready(); lcd.cls(); - //lcd.printf("%s\n", Question[UserIdentifier]); pc.printf("%s\n\r", Question[UserIdentifier]); - myTTS.speakf("S");//Speak command starts with "S" - myTTS.speakf("%s\r", Question[UserIdentifier]) ; //desired string to convert to speech - myTTS.speakf("\r"); //marks end of speak command - myTTS.ready(); //ready waits for speech to finish from last command with a ":" response + myTTS.speakf("S %s\r", Question[UserIdentifier]) ; //Earlier we identiified the User, and we ask user based question here + myTTS.ready(); lcd.cls(); lcd.printf("Type Answer: \n"); - pc.printf("Type Answer: \n\r"); - for(int C=0; C<4; C++){ + pc.printf("Type Answer: \n\r"); + + for(int C=0; C<4; C++){ //build array of attempted password __wfi(); PasswordTry[C]= Index + 1; - pc.printf("%d", PasswordTry[C]); - lcd.printf("%d", PasswordTry[C]); + pc.printf("%c", Keytable[Index]); + lcd.printf("%c", Keytable[Index]); //same as previous section wait(0.5); } - for(int D=0; D<4; D++){ + for(int D=0; D<4; D++){ //compares attempt password array with password if(QuestionAnswers[UserIdentifier][D]==PasswordTry[D]){ CorrectNumbersCounter1 = CorrectNumbersCounter1 + 1; } } - if(CorrectNumbersCounter1 == 4){ + if(CorrectNumbersCounter1 == 4){ //if correct pass then continue to next process lcd.cls(); lcd.printf("Answered\n"); lcd.printf("Accepted\n"); pc.printf("\n\rAnswer Accepted\n\r"); - myTTS.speakf("S");//Speak command starts with "S" - myTTS.speakf("Answer Accepted"); // Send the desired string to convert to speech - myTTS.speakf("\r"); //marks end of speak command - myTTS.ready(); //ready waits for speech to finish from last command with a ":" respo + myTTS.speakf("S Answer Accepted \r"); + myTTS.ready(); QuestionAuthorized = 1; Attempts = 0; } - else if(CorrectNumbersCounter1 <4) { + else if(CorrectNumbersCounter1 <4) { //fail and +1 on attempt counter CorrectNumbersCounter1 = 0; lcd.cls(); lcd.printf("FAIL"); pc.printf("FAIL"); - myTTS.speakf("S");//Speak command starts with "S" - myTTS.speakf("Incorrect Entry"); // Send the desired string to convert to speech - myTTS.speakf("\r"); //marks end of speak command - myTTS.ready(); //ready waits for speech to finish from last command with a ":" response + myTTS.speakf("S Incorrect Entry \r"); + myTTS.ready(); Attempts = Attempts + 1; if(Attempts == 4){ ResetLocks(); } } - while((QuestionAuthorized == 1)){ + while((QuestionAuthorized == 1)){ //where the door opens if(PhysicalKey == 1){ if (run_once3 == 0){ lcd.cls(); + myTTS.speakf("S Welcome %s \r", UserNames[UserIdentifier]); //announces user's name + myTTS.ready(); pc.printf("Please Remove Key\n\r"); lcd.printf("Please Remove Key\n"); - myTTS.speakf("S");//Speak command starts with "S" - myTTS.speakf("Please Remove Key"); // Send the desired string to convert to speech - myTTS.speakf("\r"); //marks end of speak command + myTTS.speakf("S Please Remove Key \r"); myTTS.ready(); //ready waits for speech to finish from last command with a ":" respo run_once3 = 1; } } - else if(PhysicalKey == 1){ + else if(PhysicalKey == 0){ //when key removed go into your door that is now open run_once3 = 0; lcd.cls(); pc.printf("Key Removed\n\r"); lcd.printf("Key Removed\n"); wait(2); - DoorUnlock = 1; - myTTS.speakf("S");//Speak command starts with "S" - myTTS.speakf("Seconds until closed"); // Send the desired string to convert to speech - myTTS.speakf("\r"); //marks end of speak command - myTTS.ready(); //ready waits for speech to finish from last command with a ":" response - for(int Y=5; Y>0; --Y){ + DoorUnlock = 1; //indicates that a door has been opened + + Box[UserIdentifier]=1; //opens the specified user's door + + myTTS.speakf("S Seconds until closed \r"); + myTTS.ready(); + for(int Y=5; Y>0; --Y){ //counts down to lock the door lcd.cls(); pc.printf("Door Open For %d Seconds\n\r",Y); lcd.printf("Door Open For:\n"); lcd.printf("%d Seconds\n",Y); - myTTS.speakf("S");//Speak command starts with "S" - myTTS.speakf("%d",Y); // Send the desired string to convert to speech - myTTS.speakf("\r"); //marks end of speak command - myTTS.ready(); //ready waits for speech to finish from last command with a ":" response + myTTS.speakf("S %d \r",Y); + myTTS.ready(); } - ResetLocks(); + ResetLocks(); //locks everything lcd.cls(); pc.printf("Door Locked\n\r"); lcd.printf("Door Locked\n"); - myTTS.speakf("S");//Speak command starts with "S" - myTTS.speakf("Door Locked"); // Send the desired string to convert to speech - myTTS.speakf("\r"); //marks end of speak command - myTTS.ready(); //ready waits for speech to finish from last command with a ":" response + myTTS.speakf("S Door Locked \r"); + myTTS.ready(); wait(1); - Attempts = 0; + Attempts = 0; //resets attempts, exits loop, restarts whole process } } } } } } - else if (run_once2 == 0){ + else if (run_once2 == 0){ //enter this function once after key inserted, but it only runs once + //because of an error this has to be placed after the readible section lcd.cls(); pc.printf("Please Scan Card\n\r"); lcd.printf("Please Scan Card\n"); - myTTS.speakf("S");//Speak command starts with "S" - myTTS.speakf("Please Scan Card"); // Send the desired string to convert to speech - myTTS.speakf("\r"); //marks end of speak command - myTTS.ready(); //ready waits for speech to finish from last command with a ":" response + myTTS.speakf("S Please Scan Card \r"); + myTTS.ready(); run_once2 = 1; } - if(PhysicalKey == 0){ - run_once2 = 0; + if(PhysicalKey == 0){ //if card is correct, but key is removed at the same time, the run_once 2 has to be reseted + run_once2 = 0; //here or it wont do a function later that only runs once, the once that asks for the card + //for fucntions to operate in the correct order this has to be placed all the way below for now. } }//Second While Loop Braket }// While(1)