kl25z secure keypad 4x4 keypad with multiple passwords,users, and outputs. (buzzer)

Dependencies:   mbed TextLCD Keypad

Files at this revision

API Documentation at this revision

Comitter:
coryburke
Date:
Fri Dec 07 07:08:02 2018 +0000
Parent:
1:5461144fd540
Commit message:
keypad 4x4 for multiple users and multiple passwords

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 5461144fd540 -r 30db7d0108c1 main.cpp
--- a/main.cpp	Thu Apr 26 18:44:07 2018 +0000
+++ b/main.cpp	Fri Dec 07 07:08:02 2018 +0000
@@ -1,30 +1,38 @@
   #include "mbed.h"
   #include "Keypad.h"
 #include "TextLCD.h"
- Keypad kpad(PTC8, PTC1, PTB19, PTB18, PTC5, PTC7, PTC0, PTC9);
- Serial pc(USBTX, USBRX);
- TextLCD lcd(PTA1, PTB23, PTA2, PTC2, PTC3, PTC12, TextLCD::LCD16x2); 
-/*
-col1, col2, col3, col4,
-row1, row2, row3, row4
+
+//pin selection for keypad matrix
+
+ Keypad kpad(PTE2,PTE3,PTE4,PTE5,PTB8,PTB9,PTB10,PTB11);
+ 
+ /*
+col1, col2, col3, col4, row1, row2, row3, row4
 */
 
-const int number_of_chars = 4;
-const char pass_user1[number_of_chars] = {'1','2','3','A'};  //HA
-const char pass_user2[number_of_chars] = {'2','2','3','A'};  //FA
-const char pass_user3[number_of_chars] = {'5','2','3','A'};  //AA
-const char pass_user4[number_of_chars] = {'6','2','3','A'};  //MA
-const char pass_user5[number_of_chars] = {'7','2','3','A'};  //FF
+// serial connection to pc for debugging and troubleshooting
+ Serial pc(USBTX, USBRX);
+ 
+//define passwords of for individual users
+const uint32_t number_of_chars = 5; //password length
+const char pass_user1[number_of_chars] = {'1','2','3','4','*'}; //
+const char pass_user2[number_of_chars] = {'1','4','7','4','*'}; //
+const char pass_user3[number_of_chars] = {'0','0','0','0','0'}; //
+const char pass_user4[number_of_chars] = {'6','5','4','C','*'}; //
+const char pass_user5[number_of_chars] = {'A','A','A','A','A'}; //
 
-char enterd_pass[number_of_chars] = {' ', ' ',' ',' '};
+//choose the character length of valid passwords
+char enterd_pass[number_of_chars] = {' ',' ',' ',' ',' '};
 
+
+//initialize outputs
 DigitalOut led_red(LED_RED);
 DigitalOut led_green(LED_GREEN);
-DigitalOut active_buzzer(PTC4);  //Buzzer on pin PTC4=D9
+DigitalOut active_buzzer(PTA4);
+DigitalOut output1(PTA5);
+  //Buzzer on pin PTD4
 
-PwmOut beep(PTC4); // buzzer
-
-//Serial pc(USBTX, USBRX);
+PwmOut beep(PTD4); // buzzer
 
 int main()
 {
@@ -35,26 +43,31 @@
     int user_index3=0;
     int user_index4=0;
     int user_index5=0;
- 
-    int released =1;;
+    int j=0;
+    int flag=0;
     
+printf("\n \n PASSWORD REQUIRED \n \n ");
 
+    int released =1;
+  
+    output1=1;
+    printf("\r\n Password Entered:");
     led_green = 0;
     led_red = 0;
     active_buzzer = 0;
 
+//buzzer period select
     beep.period(0.001);
-
-    lcd.cls();
+    
     wait(0.001);
 
     
-
-    while(true) {
+do{
+    while(1) {
+        led_green = 0;
+        led_red = 0;
+        printf("Enter Password:");
         
-        lcd.locate(0,0); // col, row 
-        lcd.printf("Enter Password:");
-
         // Reading the password characters
         for(i=0; i<number_of_chars; i++) {
             key = kpad.ReadKey();
@@ -63,9 +76,7 @@
              released = 1;                       //set the flag when all keys are released
            if((key != '\0') && (released == 1)) {  //if a key is pressed AND previous key was released
         enterd_pass[i]=key; 
-        lcd.locate(i,1); // col, row             
-        lcd.printf("*"); 
-                    
+        printf("%c ",enterd_pass[i]);           
               released = 0;                       //clear the flag to indicate that key is still pressed
               }
 else
@@ -75,17 +86,15 @@
            
         }
         
-        wait(0.5);
+        wait(0.003);
         
-        lcd.locate(0,1); // col, row             
-        lcd.printf("    " ); 
-        
-        // comparing passwords
+        // comparing password entered via keypad to valid user passwords
 
       /////////    user 1    ///////////////
         for(i=0; i<number_of_chars; i++) {
             if( enterd_pass[i] == pass_user1[i] ) {
                 user_index1 = 1;
+                active_buzzer = 0;
             } else {
                 user_index1 = 0;
                 break;
@@ -130,57 +139,115 @@
                 break;
             }
         }
-//////////////////////////////////////////////////
+        
+       
+////// correct password prompts and outputs
         if( (1 == user_index1)||(2 == user_index2)||(3 == user_index3)||(4 == user_index4)||(5 == user_index5) ) {
-            pc.printf("Access granted    ");
+            printf("\r\n Passcode recognized \n \n ");
             led_red = 1;
-            active_buzzer = 1;
-            lcd.locate(0,1); // col, row
-            lcd.printf("User: ");
+            active_buzzer = 0;
+            printf("\r\n Welcome Cory Burke \n \n" );
+           
+          output1=0;
 
             if(1 == user_index1) {
-                lcd.locate(6,1); // col, row
-                lcd.printf("HA");
+                printf("\r Access granted User 1 \n \n");
+            led_red = 1;
+            active_buzzer = 0;
+            printf("\r\n Welcome User 1 \n" );
+            printf("\r User numer: 1 \n");
+            output1=0;
             }
             if(2 == user_index2) {
-                lcd.locate(6,1); // col, row
-                lcd.printf("FA");
+                printf("\r\n Access granted: User 2 \n \n ");
+            led_red = 1;
+            active_buzzer = 0;
+            printf("\r\n Welcome User 2 \n" );
+            printf("\r User numer: 2 \n");
+            output1=0;
             }
             if(3 == user_index3) {
-                lcd.locate(6,1); // col, row
-                lcd.printf("AA");
+                printf("\r\n Access granted: User 3  \n ");
+            led_red = 1;
+            active_buzzer = 0;
+            printf("\r\n Welcome User 3 \n" );
+            printf("\r User numer: 3 \n ");
+            output1=0;
             }
             if(4 == user_index4) {
-                lcd.locate(6,1); // col, row
-                lcd.printf("MA");
+                printf("\r\n Access granted: User 4   \n ");
+            led_red = 1;
+            active_buzzer = 0;
+            printf("\r\n Welcome User 4 \n" );
+            printf("\r User numer: 4 \n");
+            output1=0;
             }
             if(5 == user_index5) {
-                lcd.locate(6,1); // col, row
-                lcd.printf("FF");
+                printf("\r Access granted: User 5 \n ");
+            led_red = 1;
+            active_buzzer = 0;
+            printf("\r\n Welcome User 5 \n " );
+            printf("\r User numer: 5 \n");
+            output1=0;
             }
 
             wait(1);
-            active_buzzer = 1;
-            beep = 80.3/100.0;
+            active_buzzer = 0;
+            beep = 25.0/100.0;
             led_red = 0;
+            led_green=0;
+            output1=1;
             wait(1);
-       lcd.cls();
+      
 
 
         }
-
+// indicates that an incorrect passwords was entered with leds and buzzer
         else {
-            lcd.locate(0,0); // col, row  
-            lcd.printf("Access denied     ");
+            printf("\r\n \n Incorrect password \n \n Access denied!  \n \n  ");
+            led_green = 1;
+            led_red=0;
+            wait(1);
+            active_buzzer = 1;
+             beep = 50.0/100.0;
+            j=j+1;
+            
+            if(j==4){printf("\r\n \n TOO MANT ATTEMPTS, SYSTEM LOCKOUT  \n \n  ");
             led_green = 1;
+            led_red=0;
+            flag=1;
             wait(1);
-            led_green = 0;
-            active_buzzer = 0;
-            beep = 0.0/100.0;
-        }
+            active_buzzer = 1;
+             beep = 50.0/100.0;
+               output1=1;
+            wait(1);
+             output1=0;
+            wait(1);
+             output1=1;
+            wait(1);
+             output1=0;
+            wait(1);
+             output1=1;
+            wait(1);   
+                                                                            }
+            
+                                                                    }
         
         beep = 0.0/100.0;
-
+        led_green = 0;
+            led_red=0;
     }
+    
+    
+    
+    
+    
+    } while(flag==0);
+    
+    
+    
+    
+    
+    
 }
 
diff -r 5461144fd540 -r 30db7d0108c1 mbed.bld
--- a/mbed.bld	Thu Apr 26 18:44:07 2018 +0000
+++ b/mbed.bld	Fri Dec 07 07:08:02 2018 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/994bdf8177cb
\ No newline at end of file
+https://os.mbed.com/users/mbed_official/code/mbed/builds/3a7713b1edbc
\ No newline at end of file