Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Keypad 4x4 password login Nextion display
- * @author Simeon Baltadziev
- * @version 1.0.0 01.05.2017
- *
- */
- #include <Keypad.h>
- #include <Nextion.h>
- #define TX 2
- #define RX 3
- const byte ROWS = 4; //four rows
- const byte COLS = 4; //four columns
- int passwordLength = 6;
- char password[6] = {1,3,4,5,1,3};
- //define the cymbols on the buttons of the keypads
- char hexaKeys[ROWS][COLS] = {
- {'1','2','3','A'},
- {'4','5','6','B'},
- {'7','8','9','C'},
- {'*','0','#','D'}
- };
- byte rowPins[ROWS] = {12, 10, 9, 8}; //connect to the row pinouts of the keypad
- byte colPins[COLS] = {7, 6, 5, 4}; //connect to the column pinouts of the keypad
- //initialize an instance of class NewKeypad
- Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
- SoftwareSerial nextion(TX, RX);
- Nextion display(nextion, 9600);
- void setup(){
- Serial.begin(9600);
- display.init();
- }
- void loop(){
- char customKey = customKeypad.getKey();
- char enteredPassword[6];
- int matched = 0;
- for(int i = 0; i <=passwordLength; i++) {
- enteredPassword[i] = customKeypad.getKey();
- Serial.println("Entered char:");
- Serial.print(enteredPassword[i]);
- delay(50);
- }
- for(int j = 0; j<6; j++) {
- if(password[j] == enteredPassword[j]) {
- matched = matched +1;
- }
- }
- if(matched == passwordLength) {
- Serial.println("Successful login");
- //nextion
- }
- else {
- Serial.println("Wrong password!");
- //nextion
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment