Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Keypadlatest TextLCD
Diff: main.cpp
- Revision:
- 0:819b4e0e0ae6
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Thu Nov 16 04:41:13 2017 +0000
@@ -0,0 +1,64 @@
+
+#include "mbed.h"
+#include "Keypad.h"
+#include "TextLCD.h"
+#include "string.h"
+TextLCD display(D8, D9, D4, D5, D6, D7); // rs, e, d4-d7
+
+char kpdLayout[4][4] = {{'1' ,'2' ,'3' ,'A'}, //row0
+ {'4' ,'5' ,'6' ,'B'}, //row1
+ {'7' ,'8' ,'9' ,'C'}, //row2
+ {'*' ,'0' ,'#' ,'D'}}; //row3
+
+Keypad kpad(PB_14, PB_15, PB_1, PB_2, PB_11, PB_12, PA_11, PA_12);
+char password[20];
+const char code1[]="12345678";
+int main() {
+ char key;
+ int released = 1,count=0;
+ display.locate(0,0);
+ display.printf("insert password");
+ while(1){
+ key = kpad.ReadKey(); //read the current key pressed
+ if(key == '\0')
+ 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
+ if(key!='#')
+ { password[count]=key; // add pasword
+ password[count+1]='\0'; // put end of password
+ count++; //counter
+ if(count>8) //max count
+ count=0;
+ display.cls();
+ display.locate(0,0);
+ display.printf("insert password");
+ display.locate(2,1);
+ display.printf("pass:%s",password);
+ }
+ else if(key=='#')
+ { bool accept=1;
+ for(int i=0;password[i]!='\0';i++)
+ { if(password[i]!=code1[i])
+ { accept=0;
+ break;
+ }
+ }
+ display.cls();
+ if(accept==0)
+ { display.locate(0,0);
+ display.printf("wrong password ");
+ }
+ else
+ { display.locate(0,0);
+ display.printf("accept password");
+ }
+ count=0; // reset password counter
+ }
+
+
+
+ released = 0; //clear the flag to indicate that key is still pressed
+ }
+ }
+}