Security System
Dependencies: mbed ID12RFID TextLCD keypad
main.cpp@2:bcdd700feee0, 2021-12-04 (annotated)
- Committer:
- mabelliard
- Date:
- Sat Dec 04 10:13:46 2021 +0000
- Revision:
- 2:bcdd700feee0
- Parent:
- 1:43e6a97f7d4d
Final Copy;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mabelliard | 2:bcdd700feee0 | 1 | #include "mbed.h" //MBED library |
mabelliard | 2:bcdd700feee0 | 2 | #include "TextLCD.h" //LCD library |
mabelliard | 2:bcdd700feee0 | 3 | #include "ID12RFID.h" //RFID library |
mabelliard | 2:bcdd700feee0 | 4 | #include "Keypad.h" //Keypad library |
mabelliard | 2:bcdd700feee0 | 5 | #include "emic2.h" //Speech library |
mabelliard | 1:43e6a97f7d4d | 6 | |
mabelliard | 1:43e6a97f7d4d | 7 | |
mabelliard | 1:43e6a97f7d4d | 8 | emic2 myTTS(p13, p14); //serial RX,TX pins to emic |
mabelliard | 2:bcdd700feee0 | 9 | Serial pc(USBTX, USBRX); // Self Explanatory |
mabelliard | 2:bcdd700feee0 | 10 | ID12RFID rfid(p27); // uart rx |
mabelliard | 2:bcdd700feee0 | 11 | TextLCD lcd(p15, p16, p21, p22, p23, p24); //rs,e,d0,d1,d2,d3, Digital Out Pins |
mabelliard | 2:bcdd700feee0 | 12 | DigitalIn PhysicalKey(p5); //Digital In pin |
mabelliard | 2:bcdd700feee0 | 13 | Keypad keypad(p7, p12, p11, p9, p8, p6, p10, NC); //Digital out and Digital in Pins for Keypad |
mabelliard | 2:bcdd700feee0 | 14 | DigitalOut Box[2]={p29, p30}; //LED ligts to show what door opens at the end |
mabelliard | 0:b79709bfa1e2 | 15 | |
mabelliard | 1:43e6a97f7d4d | 16 | // Define your own keypad values |
mabelliard | 1:43e6a97f7d4d | 17 | char Keytable[] = {'1', '2', '3', // r0 |
mabelliard | 1:43e6a97f7d4d | 18 | '4', '5', '6', // r1 |
mabelliard | 1:43e6a97f7d4d | 19 | '7', '8', '9', // r2 |
mabelliard | 1:43e6a97f7d4d | 20 | '*', '0', '#'}; // r3 |
mabelliard | 1:43e6a97f7d4d | 21 | // c0 c1 c2 |
mabelliard | 2:bcdd700feee0 | 22 | |
mabelliard | 2:bcdd700feee0 | 23 | uint32_t Password[4]={1, 2, 3, 4}; //General Password is 1234 |
mabelliard | 2:bcdd700feee0 | 24 | uint32_t PasswordTry[4]; //Where your password attempt is stored |
mabelliard | 2:bcdd700feee0 | 25 | uint32_t Index; //keypad library output from 0 to 11 defined as |
mabelliard | 2:bcdd700feee0 | 26 | /* |
mabelliard | 2:bcdd700feee0 | 27 | {'0', '1', '2', // r0 |
mabelliard | 2:bcdd700feee0 | 28 | '3', '4', '5', // r1 |
mabelliard | 2:bcdd700feee0 | 29 | '6', '7', '8', // r2 |
mabelliard | 2:bcdd700feee0 | 30 | '9', '10', '11'}; // r3 |
mabelliard | 2:bcdd700feee0 | 31 | // c0 c1 c2 |
mabelliard | 2:bcdd700feee0 | 32 | */ |
mabelliard | 1:43e6a97f7d4d | 33 | |
mabelliard | 1:43e6a97f7d4d | 34 | uint32_t cbAfterInput(uint32_t index) { |
mabelliard | 2:bcdd700feee0 | 35 | Index = index; //the actual output of the library is index, we assign it to Index |
mabelliard | 1:43e6a97f7d4d | 36 | return 0; |
mabelliard | 1:43e6a97f7d4d | 37 | } |
mabelliard | 0:b79709bfa1e2 | 38 | |
mabelliard | 1:43e6a97f7d4d | 39 | //Entry Verification Levels |
mabelliard | 1:43e6a97f7d4d | 40 | DigitalOut CardAuthorized(LED1); //Authorized Card Notification |
mabelliard | 1:43e6a97f7d4d | 41 | DigitalOut PinAuthorized(LED2); //Authorized Pin Notification |
mabelliard | 2:bcdd700feee0 | 42 | DigitalOut QuestionAuthorized(LED3); //Approved Security Question |
mabelliard | 1:43e6a97f7d4d | 43 | DigitalOut DoorUnlock(LED4); //Approved Entry |
mabelliard | 0:b79709bfa1e2 | 44 | |
mabelliard | 1:43e6a97f7d4d | 45 | //Stored integers to manipulate security information |
mabelliard | 1:43e6a97f7d4d | 46 | int Attempts = 0; //Counts how many times Timer ResetEvertyhing has been triggered, and failures |
mabelliard | 1:43e6a97f7d4d | 47 | int CardDATA; //initializes the rfid.read() function early so theres no delay to display the Data |
mabelliard | 2:bcdd700feee0 | 48 | int UserIdentifier = 0; //Self Explanatory |
mabelliard | 2:bcdd700feee0 | 49 | int CorrectNumbersCounter = 0; //Used to count how many inputs of the keypad were correct in Pin section |
mabelliard | 2:bcdd700feee0 | 50 | int CorrectNumbersCounter1 = 0; //Used to count how many inputs of the keypad were correct in Question section |
mabelliard | 2:bcdd700feee0 | 51 | int SongCounter = 0; //Used to count how many correct inputs was entered to initiat the song easter egg |
mabelliard | 2:bcdd700feee0 | 52 | int Card[10]={22352713, 22374742}; //Stored value of RFID Cards |
mabelliard | 2:bcdd700feee0 | 53 | int SongEE[4]= {12, 12, 12, 12}; //Stored value for keypad input to start the song easter egg #### |
mabelliard | 2:bcdd700feee0 | 54 | int CorrectCard = 0; // |
mabelliard | 2:bcdd700feee0 | 55 | char Question[2][64]= {"What is your social security number", //Self Explanatory |
mabelliard | 2:bcdd700feee0 | 56 | "How many pets do you own"}; |
mabelliard | 2:bcdd700feee0 | 57 | char UserNames[2][10]= {"Marco", //Self Explanatory |
mabelliard | 2:bcdd700feee0 | 58 | "Chris"}; |
mabelliard | 2:bcdd700feee0 | 59 | |
mabelliard | 2:bcdd700feee0 | 60 | uint32_t QuestionAnswers[2][4]={ {5, 5, 5, 5}, //unint32_t is used because keypad library uses it |
mabelliard | 2:bcdd700feee0 | 61 | {11, 11, 11, 1} }; //and we need to compare the password to keypad entries |
mabelliard | 2:bcdd700feee0 | 62 | //0, 0, 0, 0 |
mabelliard | 2:bcdd700feee0 | 63 | |
mabelliard | 2:bcdd700feee0 | 64 | void ResetLocks(void); //resets the locks |
mabelliard | 1:43e6a97f7d4d | 65 | void ResetLocks(void){ |
mabelliard | 2:bcdd700feee0 | 66 | CardAuthorized = 0; // Reset Card |
mabelliard | 2:bcdd700feee0 | 67 | PinAuthorized = 0; // Reset Pin |
mabelliard | 2:bcdd700feee0 | 68 | QuestionAuthorized = 0; //Reset Question Asked Section |
mabelliard | 2:bcdd700feee0 | 69 | DoorUnlock = 0; //Locks the Door |
mabelliard | 2:bcdd700feee0 | 70 | CorrectCard = 0; //Resets if a correct card has been detected |
mabelliard | 2:bcdd700feee0 | 71 | CorrectNumbersCounter = 0; //Resets whether Pin entered matches Pin Answer |
mabelliard | 2:bcdd700feee0 | 72 | CorrectNumbersCounter1 = 0;//Resets whether Pin entered mathes Question Answer |
mabelliard | 2:bcdd700feee0 | 73 | UserIdentifier = 0; //Identfies the User, default being 0, aka Marco |
mabelliard | 2:bcdd700feee0 | 74 | SongCounter = 0; //Resets the easter egg |
mabelliard | 2:bcdd700feee0 | 75 | Box[0]=0; //Closes the Door 0 for Marco |
mabelliard | 2:bcdd700feee0 | 76 | Box[1]=0; //Closes the Door 1 for Chris |
mabelliard | 1:43e6a97f7d4d | 77 | } |
mabelliard | 2:bcdd700feee0 | 78 | |
mabelliard | 1:43e6a97f7d4d | 79 | int main(){ |
mabelliard | 2:bcdd700feee0 | 80 | myTTS.volume(18); //max volume |
mabelliard | 1:43e6a97f7d4d | 81 | keypad.attach(&cbAfterInput); |
mabelliard | 1:43e6a97f7d4d | 82 | keypad.start(); // energize the keypad via c0-c3 |
mabelliard | 2:bcdd700feee0 | 83 | int run_once1 = 0; //neccesary to run a statement once in a while loop |
mabelliard | 2:bcdd700feee0 | 84 | int run_once2 = 0; //neccesary to run a statement once in a while loop |
mabelliard | 2:bcdd700feee0 | 85 | int run_once3 = 0; //neccesary to run a statement once in a while loop |
mabelliard | 2:bcdd700feee0 | 86 | myTTS.voice(2); //sets the voice profile of the speech module |
mabelliard | 2:bcdd700feee0 | 87 | |
mabelliard | 2:bcdd700feee0 | 88 | while(1){ //where the program mainly runs continuously |
mabelliard | 1:43e6a97f7d4d | 89 | while(PhysicalKey == 0) { //key either not inserted and/or turned |
mabelliard | 2:bcdd700feee0 | 90 | if (run_once1 == 0){ //run the function below once to avoid spam |
mabelliard | 2:bcdd700feee0 | 91 | ResetLocks(); //When key isnt inserted, lock everything |
mabelliard | 2:bcdd700feee0 | 92 | lcd.cls(); //clear screen |
mabelliard | 2:bcdd700feee0 | 93 | pc.printf("Please Insert Physical Key\n\r"); //Terminal Print |
mabelliard | 2:bcdd700feee0 | 94 | lcd.printf("Please Insert Physical Key \n"); //LCD Print |
mabelliard | 2:bcdd700feee0 | 95 | myTTS.speakf("S Please Insert Physical Key \r"); //S starts speech for desired string, \r ends speech |
mabelliard | 2:bcdd700feee0 | 96 | myTTS.ready(); //ready waits for speech to finish from last command |
mabelliard | 1:43e6a97f7d4d | 97 | run_once1 = 1; |
mabelliard | 0:b79709bfa1e2 | 98 | } |
mabelliard | 0:b79709bfa1e2 | 99 | } |
mabelliard | 1:43e6a97f7d4d | 100 | while(PhysicalKey == 1) { //key inserted and turned |
mabelliard | 1:43e6a97f7d4d | 101 | run_once1 = 0; |
mabelliard | 1:43e6a97f7d4d | 102 | if (run_once2 == 0){ |
mabelliard | 2:bcdd700feee0 | 103 | lcd.cls(); // |
mabelliard | 2:bcdd700feee0 | 104 | pc.printf("Please Scan Card\n\r"); // |
mabelliard | 1:43e6a97f7d4d | 105 | lcd.printf("Please Scan Card \n"); |
mabelliard | 2:bcdd700feee0 | 106 | myTTS.speakf("S Please Scan Card \r"); |
mabelliard | 2:bcdd700feee0 | 107 | myTTS.ready(); |
mabelliard | 1:43e6a97f7d4d | 108 | run_once2 = 1; |
mabelliard | 1:43e6a97f7d4d | 109 | } |
mabelliard | 2:bcdd700feee0 | 110 | else if (Attempts > 3) { //if you fail any step more than 3 times, this function startys |
mabelliard | 1:43e6a97f7d4d | 111 | lcd.cls(); |
mabelliard | 1:43e6a97f7d4d | 112 | pc.printf("Too many Attempts\n\r"); |
mabelliard | 1:43e6a97f7d4d | 113 | lcd.printf("Too many Attempts\n"); |
mabelliard | 2:bcdd700feee0 | 114 | myTTS.speakf("S Too many Attempts \r"); |
mabelliard | 2:bcdd700feee0 | 115 | myTTS.ready(); |
mabelliard | 1:43e6a97f7d4d | 116 | lcd.cls(); |
mabelliard | 1:43e6a97f7d4d | 117 | pc.printf("LOCKED for 30 Minutes\n\r"); |
mabelliard | 1:43e6a97f7d4d | 118 | lcd.printf("LOCKED for 30 Minutes\n"); |
mabelliard | 2:bcdd700feee0 | 119 | myTTS.speakf("S Locked for 30 Minutes \r"); |
mabelliard | 2:bcdd700feee0 | 120 | myTTS.ready(); |
mabelliard | 1:43e6a97f7d4d | 121 | |
mabelliard | 2:bcdd700feee0 | 122 | for(int LockedOut = 30; LockedOut>0; LockedOut--){ //Lockout Timer |
mabelliard | 2:bcdd700feee0 | 123 | lcd.cls(); |
mabelliard | 2:bcdd700feee0 | 124 | lcd.printf("Time Remaining:"); |
mabelliard | 2:bcdd700feee0 | 125 | lcd.printf("\n%d Minutes", LockedOut); |
mabelliard | 2:bcdd700feee0 | 126 | wait(60); |
mabelliard | 2:bcdd700feee0 | 127 | } |
mabelliard | 1:43e6a97f7d4d | 128 | Attempts = 0; |
mabelliard | 1:43e6a97f7d4d | 129 | } |
mabelliard | 2:bcdd700feee0 | 130 | |
mabelliard | 2:bcdd700feee0 | 131 | else if((rfid.readable())&&(Attempts < 4)) { //if the RFID Reader has a Value stored and attempts less than 4 |
mabelliard | 1:43e6a97f7d4d | 132 | lcd.cls(); |
mabelliard | 1:43e6a97f7d4d | 133 | CardDATA = rfid.read(); |
mabelliard | 1:43e6a97f7d4d | 134 | pc.printf("RFID Tag Number:%d\n\r",CardDATA); |
mabelliard | 1:43e6a97f7d4d | 135 | lcd.printf("RFID Tag Number:%d\n",CardDATA); |
mabelliard | 1:43e6a97f7d4d | 136 | wait(1); |
mabelliard | 2:bcdd700feee0 | 137 | for(int Z = 0; Z<100; Z++){ |
mabelliard | 1:43e6a97f7d4d | 138 | if(CardDATA==Card[Z]){ |
mabelliard | 2:bcdd700feee0 | 139 | UserIdentifier = Z; //Whatever Z is when the correct card is Scan is the User |
mabelliard | 2:bcdd700feee0 | 140 | CorrectCard = CorrectCard + 1; //+1 on counter if anything from CARD[Z] = card read |
mabelliard | 1:43e6a97f7d4d | 141 | } |
mabelliard | 1:43e6a97f7d4d | 142 | } |
mabelliard | 2:bcdd700feee0 | 143 | if(CorrectCard == 0){ //enter this function if the wrong card was read |
mabelliard | 1:43e6a97f7d4d | 144 | lcd.cls(); |
mabelliard | 2:bcdd700feee0 | 145 | lcd.printf("Incorrect\n"); |
mabelliard | 2:bcdd700feee0 | 146 | pc.printf("Try Again\n\r"); |
mabelliard | 2:bcdd700feee0 | 147 | myTTS.speakf("S Try Again \r"); |
mabelliard | 2:bcdd700feee0 | 148 | myTTS.ready(); |
mabelliard | 2:bcdd700feee0 | 149 | Attempts = Attempts + 1; |
mabelliard | 1:43e6a97f7d4d | 150 | wait(2); |
mabelliard | 1:43e6a97f7d4d | 151 | } |
mabelliard | 2:bcdd700feee0 | 152 | else if(CorrectCard == 1){ //enter this function if the right card was read |
mabelliard | 1:43e6a97f7d4d | 153 | CorrectCard = 0; |
mabelliard | 1:43e6a97f7d4d | 154 | lcd.cls(); |
mabelliard | 1:43e6a97f7d4d | 155 | lcd.printf("Card Accepted\n"); |
mabelliard | 1:43e6a97f7d4d | 156 | pc.printf("Card Accepted\n\r"); |
mabelliard | 1:43e6a97f7d4d | 157 | wait(2); |
mabelliard | 1:43e6a97f7d4d | 158 | CardAuthorized = 1; |
mabelliard | 1:43e6a97f7d4d | 159 | Attempts = 0; |
mabelliard | 1:43e6a97f7d4d | 160 | ////////////////////Beginning of Keypad Section |
mabelliard | 1:43e6a97f7d4d | 161 | while ((CardAuthorized == 1)&& (PhysicalKey == 1)) { |
mabelliard | 1:43e6a97f7d4d | 162 | lcd.cls(); |
mabelliard | 1:43e6a97f7d4d | 163 | lcd.printf("Type Pin: "); |
mabelliard | 1:43e6a97f7d4d | 164 | pc.printf("Type Pin: "); |
mabelliard | 2:bcdd700feee0 | 165 | myTTS.speakf("S Type Common Pin \r"); |
mabelliard | 2:bcdd700feee0 | 166 | myTTS.ready(); |
mabelliard | 1:43e6a97f7d4d | 167 | for(int A=0; A<4; A++){ |
mabelliard | 1:43e6a97f7d4d | 168 | __wfi(); |
mabelliard | 2:bcdd700feee0 | 169 | PasswordTry[A]= Index + 1; //Index +1 because index is 0 to 11, instead of 1 to 12 |
mabelliard | 2:bcdd700feee0 | 170 | lcd.printf("%c", Keytable[Index]); //prints keytable |
mabelliard | 1:43e6a97f7d4d | 171 | pc.printf("%c", Keytable[Index]); |
mabelliard | 2:bcdd700feee0 | 172 | wait(0.2); |
mabelliard | 1:43e6a97f7d4d | 173 | } |
mabelliard | 1:43e6a97f7d4d | 174 | for(int B=0; B<4; B++){ |
mabelliard | 1:43e6a97f7d4d | 175 | if(PasswordTry[B]==Password[B]){ |
mabelliard | 2:bcdd700feee0 | 176 | CorrectNumbersCounter = CorrectNumbersCounter + 1; //counts how many times Each array equal each other |
mabelliard | 1:43e6a97f7d4d | 177 | } |
mabelliard | 1:43e6a97f7d4d | 178 | } |
mabelliard | 2:bcdd700feee0 | 179 | for(int Song=0; Song<4; Song++){ //checks if the song array is equal to password try array |
mabelliard | 1:43e6a97f7d4d | 180 | if(PasswordTry[Song]==SongEE[Song]){ |
mabelliard | 1:43e6a97f7d4d | 181 | SongCounter = SongCounter + 1; |
mabelliard | 1:43e6a97f7d4d | 182 | } |
mabelliard | 1:43e6a97f7d4d | 183 | } |
mabelliard | 2:bcdd700feee0 | 184 | if(SongCounter == 4){ //plays song |
mabelliard | 1:43e6a97f7d4d | 185 | lcd.cls(); |
mabelliard | 1:43e6a97f7d4d | 186 | lcd.printf("Easter Egg ON\n"); |
mabelliard | 1:43e6a97f7d4d | 187 | pc.printf("\n\rEaster Egg ON\n\r"); |
mabelliard | 1:43e6a97f7d4d | 188 | myTTS.speakf("D1\r");//Sing Song Demo |
mabelliard | 1:43e6a97f7d4d | 189 | myTTS.ready(); //member function wait |
mabelliard | 1:43e6a97f7d4d | 190 | SongCounter = 0; |
mabelliard | 1:43e6a97f7d4d | 191 | } |
mabelliard | 2:bcdd700feee0 | 192 | else if(CorrectNumbersCounter == 4){ //Continues program if pin is correct |
mabelliard | 1:43e6a97f7d4d | 193 | SongCounter = 0; |
mabelliard | 1:43e6a97f7d4d | 194 | lcd.cls(); |
mabelliard | 1:43e6a97f7d4d | 195 | lcd.printf("Pin Accepted\n"); |
mabelliard | 1:43e6a97f7d4d | 196 | pc.printf("\n\rPin Accepted\n\r"); |
mabelliard | 1:43e6a97f7d4d | 197 | wait(2); |
mabelliard | 1:43e6a97f7d4d | 198 | PinAuthorized = 1; |
mabelliard | 1:43e6a97f7d4d | 199 | Attempts = 0; |
mabelliard | 1:43e6a97f7d4d | 200 | } |
mabelliard | 2:bcdd700feee0 | 201 | else if (CorrectNumbersCounter < 4){//if pin is incorrect, adds 1 attempt |
mabelliard | 1:43e6a97f7d4d | 202 | SongCounter= 0; |
mabelliard | 1:43e6a97f7d4d | 203 | CorrectNumbersCounter = 0; |
mabelliard | 1:43e6a97f7d4d | 204 | lcd.cls(); |
mabelliard | 1:43e6a97f7d4d | 205 | lcd.printf("FAIL"); |
mabelliard | 1:43e6a97f7d4d | 206 | pc.printf("FAIL"); |
mabelliard | 2:bcdd700feee0 | 207 | myTTS.speakf("S Incorrect Entry \r"); |
mabelliard | 2:bcdd700feee0 | 208 | myTTS.ready(); |
mabelliard | 1:43e6a97f7d4d | 209 | Attempts = Attempts + 1; |
mabelliard | 1:43e6a97f7d4d | 210 | if(Attempts == 4){ |
mabelliard | 1:43e6a97f7d4d | 211 | ResetLocks(); |
mabelliard | 1:43e6a97f7d4d | 212 | } |
mabelliard | 1:43e6a97f7d4d | 213 | } |
mabelliard | 2:bcdd700feee0 | 214 | while ((PinAuthorized == 1)&&(PhysicalKey == 1)) { //if the pin turned on Pinauthorized earlier enter funtion |
mabelliard | 2:bcdd700feee0 | 215 | //security question section, Everything in this section is identical to the previous section, except for the question part |
mabelliard | 1:43e6a97f7d4d | 216 | lcd.cls(); |
mabelliard | 1:43e6a97f7d4d | 217 | lcd.printf("Security\n"); |
mabelliard | 1:43e6a97f7d4d | 218 | lcd.printf("Question\n"); |
mabelliard | 1:43e6a97f7d4d | 219 | pc.printf("Security Question\n\r"); |
mabelliard | 2:bcdd700feee0 | 220 | myTTS.speakf("S Security Question \r"); |
mabelliard | 1:43e6a97f7d4d | 221 | myTTS.speakf("\r"); //marks end of speak command |
mabelliard | 2:bcdd700feee0 | 222 | myTTS.ready(); |
mabelliard | 1:43e6a97f7d4d | 223 | lcd.cls(); |
mabelliard | 1:43e6a97f7d4d | 224 | pc.printf("%s\n\r", Question[UserIdentifier]); |
mabelliard | 2:bcdd700feee0 | 225 | myTTS.speakf("S %s\r", Question[UserIdentifier]) ; //Earlier we identiified the User, and we ask user based question here |
mabelliard | 2:bcdd700feee0 | 226 | myTTS.ready(); |
mabelliard | 1:43e6a97f7d4d | 227 | lcd.cls(); |
mabelliard | 1:43e6a97f7d4d | 228 | lcd.printf("Type Answer: \n"); |
mabelliard | 2:bcdd700feee0 | 229 | pc.printf("Type Answer: \n\r"); |
mabelliard | 2:bcdd700feee0 | 230 | |
mabelliard | 2:bcdd700feee0 | 231 | for(int C=0; C<4; C++){ //build array of attempted password |
mabelliard | 1:43e6a97f7d4d | 232 | __wfi(); |
mabelliard | 1:43e6a97f7d4d | 233 | PasswordTry[C]= Index + 1; |
mabelliard | 2:bcdd700feee0 | 234 | pc.printf("%c", Keytable[Index]); |
mabelliard | 2:bcdd700feee0 | 235 | lcd.printf("%c", Keytable[Index]); //same as previous section |
mabelliard | 1:43e6a97f7d4d | 236 | wait(0.5); |
mabelliard | 1:43e6a97f7d4d | 237 | } |
mabelliard | 2:bcdd700feee0 | 238 | for(int D=0; D<4; D++){ //compares attempt password array with password |
mabelliard | 1:43e6a97f7d4d | 239 | if(QuestionAnswers[UserIdentifier][D]==PasswordTry[D]){ |
mabelliard | 1:43e6a97f7d4d | 240 | CorrectNumbersCounter1 = CorrectNumbersCounter1 + 1; |
mabelliard | 1:43e6a97f7d4d | 241 | } |
mabelliard | 1:43e6a97f7d4d | 242 | } |
mabelliard | 2:bcdd700feee0 | 243 | if(CorrectNumbersCounter1 == 4){ //if correct pass then continue to next process |
mabelliard | 1:43e6a97f7d4d | 244 | lcd.cls(); |
mabelliard | 1:43e6a97f7d4d | 245 | lcd.printf("Answered\n"); |
mabelliard | 1:43e6a97f7d4d | 246 | lcd.printf("Accepted\n"); |
mabelliard | 1:43e6a97f7d4d | 247 | pc.printf("\n\rAnswer Accepted\n\r"); |
mabelliard | 2:bcdd700feee0 | 248 | myTTS.speakf("S Answer Accepted \r"); |
mabelliard | 2:bcdd700feee0 | 249 | myTTS.ready(); |
mabelliard | 1:43e6a97f7d4d | 250 | QuestionAuthorized = 1; |
mabelliard | 1:43e6a97f7d4d | 251 | Attempts = 0; |
mabelliard | 1:43e6a97f7d4d | 252 | } |
mabelliard | 2:bcdd700feee0 | 253 | else if(CorrectNumbersCounter1 <4) { //fail and +1 on attempt counter |
mabelliard | 1:43e6a97f7d4d | 254 | CorrectNumbersCounter1 = 0; |
mabelliard | 1:43e6a97f7d4d | 255 | lcd.cls(); |
mabelliard | 1:43e6a97f7d4d | 256 | lcd.printf("FAIL"); |
mabelliard | 1:43e6a97f7d4d | 257 | pc.printf("FAIL"); |
mabelliard | 2:bcdd700feee0 | 258 | myTTS.speakf("S Incorrect Entry \r"); |
mabelliard | 2:bcdd700feee0 | 259 | myTTS.ready(); |
mabelliard | 1:43e6a97f7d4d | 260 | Attempts = Attempts + 1; |
mabelliard | 1:43e6a97f7d4d | 261 | if(Attempts == 4){ |
mabelliard | 1:43e6a97f7d4d | 262 | ResetLocks(); |
mabelliard | 1:43e6a97f7d4d | 263 | } |
mabelliard | 1:43e6a97f7d4d | 264 | } |
mabelliard | 1:43e6a97f7d4d | 265 | |
mabelliard | 2:bcdd700feee0 | 266 | while((QuestionAuthorized == 1)){ //where the door opens |
mabelliard | 1:43e6a97f7d4d | 267 | if(PhysicalKey == 1){ |
mabelliard | 1:43e6a97f7d4d | 268 | if (run_once3 == 0){ |
mabelliard | 1:43e6a97f7d4d | 269 | lcd.cls(); |
mabelliard | 2:bcdd700feee0 | 270 | myTTS.speakf("S Welcome %s \r", UserNames[UserIdentifier]); //announces user's name |
mabelliard | 2:bcdd700feee0 | 271 | myTTS.ready(); |
mabelliard | 1:43e6a97f7d4d | 272 | pc.printf("Please Remove Key\n\r"); |
mabelliard | 1:43e6a97f7d4d | 273 | lcd.printf("Please Remove Key\n"); |
mabelliard | 2:bcdd700feee0 | 274 | myTTS.speakf("S Please Remove Key \r"); |
mabelliard | 1:43e6a97f7d4d | 275 | myTTS.ready(); //ready waits for speech to finish from last command with a ":" respo |
mabelliard | 1:43e6a97f7d4d | 276 | run_once3 = 1; |
mabelliard | 1:43e6a97f7d4d | 277 | } |
mabelliard | 1:43e6a97f7d4d | 278 | } |
mabelliard | 2:bcdd700feee0 | 279 | else if(PhysicalKey == 0){ //when key removed go into your door that is now open |
mabelliard | 1:43e6a97f7d4d | 280 | run_once3 = 0; |
mabelliard | 1:43e6a97f7d4d | 281 | lcd.cls(); |
mabelliard | 1:43e6a97f7d4d | 282 | pc.printf("Key Removed\n\r"); |
mabelliard | 1:43e6a97f7d4d | 283 | lcd.printf("Key Removed\n"); |
mabelliard | 1:43e6a97f7d4d | 284 | wait(2); |
mabelliard | 2:bcdd700feee0 | 285 | DoorUnlock = 1; //indicates that a door has been opened |
mabelliard | 2:bcdd700feee0 | 286 | |
mabelliard | 2:bcdd700feee0 | 287 | Box[UserIdentifier]=1; //opens the specified user's door |
mabelliard | 2:bcdd700feee0 | 288 | |
mabelliard | 2:bcdd700feee0 | 289 | myTTS.speakf("S Seconds until closed \r"); |
mabelliard | 2:bcdd700feee0 | 290 | myTTS.ready(); |
mabelliard | 2:bcdd700feee0 | 291 | for(int Y=5; Y>0; --Y){ //counts down to lock the door |
mabelliard | 1:43e6a97f7d4d | 292 | lcd.cls(); |
mabelliard | 1:43e6a97f7d4d | 293 | pc.printf("Door Open For %d Seconds\n\r",Y); |
mabelliard | 1:43e6a97f7d4d | 294 | lcd.printf("Door Open For:\n"); |
mabelliard | 1:43e6a97f7d4d | 295 | lcd.printf("%d Seconds\n",Y); |
mabelliard | 2:bcdd700feee0 | 296 | myTTS.speakf("S %d \r",Y); |
mabelliard | 2:bcdd700feee0 | 297 | myTTS.ready(); |
mabelliard | 1:43e6a97f7d4d | 298 | } |
mabelliard | 2:bcdd700feee0 | 299 | ResetLocks(); //locks everything |
mabelliard | 1:43e6a97f7d4d | 300 | lcd.cls(); |
mabelliard | 1:43e6a97f7d4d | 301 | pc.printf("Door Locked\n\r"); |
mabelliard | 1:43e6a97f7d4d | 302 | lcd.printf("Door Locked\n"); |
mabelliard | 2:bcdd700feee0 | 303 | myTTS.speakf("S Door Locked \r"); |
mabelliard | 2:bcdd700feee0 | 304 | myTTS.ready(); |
mabelliard | 1:43e6a97f7d4d | 305 | wait(1); |
mabelliard | 2:bcdd700feee0 | 306 | Attempts = 0; //resets attempts, exits loop, restarts whole process |
mabelliard | 1:43e6a97f7d4d | 307 | } |
mabelliard | 1:43e6a97f7d4d | 308 | } |
mabelliard | 1:43e6a97f7d4d | 309 | } |
mabelliard | 1:43e6a97f7d4d | 310 | } |
mabelliard | 1:43e6a97f7d4d | 311 | } |
mabelliard | 1:43e6a97f7d4d | 312 | } |
mabelliard | 2:bcdd700feee0 | 313 | else if (run_once2 == 0){ //enter this function once after key inserted, but it only runs once |
mabelliard | 2:bcdd700feee0 | 314 | //because of an error this has to be placed after the readible section |
mabelliard | 1:43e6a97f7d4d | 315 | lcd.cls(); |
mabelliard | 1:43e6a97f7d4d | 316 | pc.printf("Please Scan Card\n\r"); |
mabelliard | 1:43e6a97f7d4d | 317 | lcd.printf("Please Scan Card\n"); |
mabelliard | 2:bcdd700feee0 | 318 | myTTS.speakf("S Please Scan Card \r"); |
mabelliard | 2:bcdd700feee0 | 319 | myTTS.ready(); |
mabelliard | 1:43e6a97f7d4d | 320 | run_once2 = 1; |
mabelliard | 1:43e6a97f7d4d | 321 | } |
mabelliard | 2:bcdd700feee0 | 322 | if(PhysicalKey == 0){ //if card is correct, but key is removed at the same time, the run_once 2 has to be reseted |
mabelliard | 2:bcdd700feee0 | 323 | run_once2 = 0; //here or it wont do a function later that only runs once, the once that asks for the card |
mabelliard | 2:bcdd700feee0 | 324 | //for fucntions to operate in the correct order this has to be placed all the way below for now. |
mabelliard | 1:43e6a97f7d4d | 325 | } |
mabelliard | 1:43e6a97f7d4d | 326 | }//Second While Loop Braket |
mabelliard | 1:43e6a97f7d4d | 327 | }// While(1) |
mabelliard | 1:43e6a97f7d4d | 328 | }//Main Braket |