kl25z secure keypad 4x4 keypad with multiple passwords,users, and outputs. (buzzer)
Dependencies: mbed TextLCD Keypad
main.cpp
00001 #include "mbed.h" 00002 #include "Keypad.h" 00003 #include "TextLCD.h" 00004 00005 //pin selection for keypad matrix 00006 00007 Keypad kpad(PTE2,PTE3,PTE4,PTE5,PTB8,PTB9,PTB10,PTB11); 00008 00009 /* 00010 col1, col2, col3, col4, row1, row2, row3, row4 00011 */ 00012 00013 // serial connection to pc for debugging and troubleshooting 00014 Serial pc(USBTX, USBRX); 00015 00016 //define passwords of for individual users 00017 const uint32_t number_of_chars = 5; //password length 00018 const char pass_user1[number_of_chars] = {'1','2','3','4','*'}; // 00019 const char pass_user2[number_of_chars] = {'1','4','7','4','*'}; // 00020 const char pass_user3[number_of_chars] = {'0','0','0','0','0'}; // 00021 const char pass_user4[number_of_chars] = {'6','5','4','C','*'}; // 00022 const char pass_user5[number_of_chars] = {'A','A','A','A','A'}; // 00023 00024 //choose the character length of valid passwords 00025 char enterd_pass[number_of_chars] = {' ',' ',' ',' ',' '}; 00026 00027 00028 //initialize outputs 00029 DigitalOut led_red(LED_RED); 00030 DigitalOut led_green(LED_GREEN); 00031 DigitalOut active_buzzer(PTA4); 00032 DigitalOut output1(PTA5); 00033 //Buzzer on pin PTD4 00034 00035 PwmOut beep(PTD4); // buzzer 00036 00037 int main() 00038 { 00039 char key; 00040 int i; 00041 int user_index1=0; 00042 int user_index2=0; 00043 int user_index3=0; 00044 int user_index4=0; 00045 int user_index5=0; 00046 int j=0; 00047 int flag=0; 00048 00049 printf("\n \n PASSWORD REQUIRED \n \n "); 00050 00051 int released =1; 00052 00053 output1=1; 00054 printf("\r\n Password Entered:"); 00055 led_green = 0; 00056 led_red = 0; 00057 active_buzzer = 0; 00058 00059 //buzzer period select 00060 beep.period(0.001); 00061 00062 wait(0.001); 00063 00064 00065 do{ 00066 while(1) { 00067 led_green = 0; 00068 led_red = 0; 00069 printf("Enter Password:"); 00070 00071 // Reading the password characters 00072 for(i=0; i<number_of_chars; i++) { 00073 key = kpad.ReadKey(); 00074 00075 if(key == '\0') 00076 released = 1; //set the flag when all keys are released 00077 if((key != '\0') && (released == 1)) { //if a key is pressed AND previous key was released 00078 enterd_pass[i]=key; 00079 printf("%c ",enterd_pass[i]); 00080 released = 0; //clear the flag to indicate that key is still pressed 00081 } 00082 else 00083 i--; 00084 00085 00086 00087 } 00088 00089 wait(0.003); 00090 00091 // comparing password entered via keypad to valid user passwords 00092 00093 ///////// user 1 /////////////// 00094 for(i=0; i<number_of_chars; i++) { 00095 if( enterd_pass[i] == pass_user1[i] ) { 00096 user_index1 = 1; 00097 active_buzzer = 0; 00098 } else { 00099 user_index1 = 0; 00100 break; 00101 } 00102 } 00103 00104 00105 00106 ///////// user 2 /////////////// 00107 for(i=0; i<number_of_chars; i++) { 00108 if( enterd_pass[i] == pass_user2[i] ) { 00109 user_index2 = 2; 00110 } else { 00111 user_index2 = 0; 00112 break; 00113 } 00114 } 00115 ///////// user 3 /////////////// 00116 for(i=0; i<number_of_chars; i++) { 00117 if( enterd_pass[i] == pass_user3[i] ) { 00118 user_index3 = 3; 00119 } else { 00120 user_index3 = 0; 00121 break; 00122 } 00123 } 00124 ///////// user 4 /////////////// 00125 for(i=0; i<number_of_chars; i++) { 00126 if( enterd_pass[i] == pass_user4[i] ) { 00127 user_index4 = 4; 00128 } else { 00129 user_index4 = 0; 00130 break; 00131 } 00132 } 00133 ///////// user 5 /////////////// 00134 for(i=0; i<number_of_chars; i++) { 00135 if( enterd_pass[i] == pass_user5[i] ) { 00136 user_index5 = 5; 00137 } else { 00138 user_index5 = 0; 00139 break; 00140 } 00141 } 00142 00143 00144 ////// correct password prompts and outputs 00145 if( (1 == user_index1)||(2 == user_index2)||(3 == user_index3)||(4 == user_index4)||(5 == user_index5) ) { 00146 printf("\r\n Passcode recognized \n \n "); 00147 led_red = 1; 00148 active_buzzer = 0; 00149 printf("\r\n Welcome Cory Burke \n \n" ); 00150 00151 output1=0; 00152 00153 if(1 == user_index1) { 00154 printf("\r Access granted User 1 \n \n"); 00155 led_red = 1; 00156 active_buzzer = 0; 00157 printf("\r\n Welcome User 1 \n" ); 00158 printf("\r User numer: 1 \n"); 00159 output1=0; 00160 } 00161 if(2 == user_index2) { 00162 printf("\r\n Access granted: User 2 \n \n "); 00163 led_red = 1; 00164 active_buzzer = 0; 00165 printf("\r\n Welcome User 2 \n" ); 00166 printf("\r User numer: 2 \n"); 00167 output1=0; 00168 } 00169 if(3 == user_index3) { 00170 printf("\r\n Access granted: User 3 \n "); 00171 led_red = 1; 00172 active_buzzer = 0; 00173 printf("\r\n Welcome User 3 \n" ); 00174 printf("\r User numer: 3 \n "); 00175 output1=0; 00176 } 00177 if(4 == user_index4) { 00178 printf("\r\n Access granted: User 4 \n "); 00179 led_red = 1; 00180 active_buzzer = 0; 00181 printf("\r\n Welcome User 4 \n" ); 00182 printf("\r User numer: 4 \n"); 00183 output1=0; 00184 } 00185 if(5 == user_index5) { 00186 printf("\r Access granted: User 5 \n "); 00187 led_red = 1; 00188 active_buzzer = 0; 00189 printf("\r\n Welcome User 5 \n " ); 00190 printf("\r User numer: 5 \n"); 00191 output1=0; 00192 } 00193 00194 wait(1); 00195 active_buzzer = 0; 00196 beep = 25.0/100.0; 00197 led_red = 0; 00198 led_green=0; 00199 output1=1; 00200 wait(1); 00201 00202 00203 00204 } 00205 // indicates that an incorrect passwords was entered with leds and buzzer 00206 else { 00207 printf("\r\n \n Incorrect password \n \n Access denied! \n \n "); 00208 led_green = 1; 00209 led_red=0; 00210 wait(1); 00211 active_buzzer = 1; 00212 beep = 50.0/100.0; 00213 j=j+1; 00214 00215 if(j==4){printf("\r\n \n TOO MANT ATTEMPTS, SYSTEM LOCKOUT \n \n "); 00216 led_green = 1; 00217 led_red=0; 00218 flag=1; 00219 wait(1); 00220 active_buzzer = 1; 00221 beep = 50.0/100.0; 00222 output1=1; 00223 wait(1); 00224 output1=0; 00225 wait(1); 00226 output1=1; 00227 wait(1); 00228 output1=0; 00229 wait(1); 00230 output1=1; 00231 wait(1); 00232 } 00233 00234 } 00235 00236 beep = 0.0/100.0; 00237 led_green = 0; 00238 led_red=0; 00239 } 00240 00241 00242 00243 00244 00245 } while(flag==0); 00246 00247 00248 00249 00250 00251 00252 } 00253
Generated on Mon Aug 15 2022 08:38:11 by 1.7.2