saimun1

ArrayPassword WIP

May 1st, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.52 KB | None | 0 0
  1. /**
  2.  * Keypad   4x4 password login Nextion display
  3.  * @author  Simeon Baltadziev
  4.  * @version 1.0.0 01.05.2017
  5.  *
  6.  */
  7. #include <Keypad.h>
  8. #include <Nextion.h>
  9. #define TX 2
  10. #define RX 3
  11.  
  12. const byte ROWS = 4; //four rows
  13. const byte COLS = 4; //four columns
  14. int passwordLength = 6;
  15. char password[6] = {1,3,4,5,1,3};
  16. //define the cymbols on the buttons of the keypads
  17.  
  18. char hexaKeys[ROWS][COLS] = {
  19.   {'1','2','3','A'},
  20.   {'4','5','6','B'},
  21.   {'7','8','9','C'},
  22.   {'*','0','#','D'}
  23. };
  24. byte rowPins[ROWS] = {12, 10, 9, 8}; //connect to the row pinouts of the keypad
  25. byte colPins[COLS] = {7, 6, 5, 4}; //connect to the column pinouts of the keypad
  26.  
  27. //initialize an instance of class NewKeypad
  28. Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
  29.  
  30. SoftwareSerial nextion(TX, RX);
  31. Nextion display(nextion, 9600);
  32.  
  33.  
  34. void setup(){
  35.   Serial.begin(9600);
  36.   display.init();
  37. }
  38.  
  39. void loop(){
  40.   char customKey = customKeypad.getKey();
  41.   char enteredPassword[6];
  42.   int matched = 0;
  43.   for(int i = 0; i <=passwordLength; i++) {
  44.        
  45.      enteredPassword[i] = customKeypad.getKey();
  46.      Serial.println("Entered char:");
  47.      Serial.print(enteredPassword[i]);
  48.      delay(50);
  49.      
  50.   }
  51.  
  52.  for(int j = 0; j<6; j++) {
  53.      if(password[j] == enteredPassword[j]) {
  54.      matched = matched +1;
  55.  
  56.      }
  57.    }
  58.  
  59.    if(matched ==  passwordLength) {
  60.     Serial.println("Successful login");
  61.     //nextion
  62.    }
  63.    else {
  64.     Serial.println("Wrong password!");
  65.     //nextion
  66.    }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment