Guest User

Untitled

a guest
Nov 23rd, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. #include <Keypad.h>
  2. #include <Password.h>
  3.  
  4. #define rows 4
  5. #define cols 3
  6.  
  7. #define keyLED 11
  8. #define correctLED 12
  9. #define wrongLED 13
  10.  
  11. char keys[rows][cols] = {
  12. {&#039;1&#039;,&#039;2&#039;,&#039;3&#039;},
  13. {&#039;4&#039;,&#039;5&#039;,&#039;6&#039;},
  14. {&#039;7&#039;,&#039;8&#039;,&#039;9&#039;},
  15. {&#039;*&#039;,&#039;0&#039;,&#039;#&#039;}
  16. };
  17.  
  18. byte rowPins[rows] = {2,3,4,5};
  19. byte colPins[cols] = {6,7,8};
  20.  
  21. Keypad keypad = Keypad(makeKeymap(keys),rowPins,colPins,rows,cols);
  22.  
  23. Password password = Password("1234");
  24.  
  25. void setup() {
  26. pinMode(keyLED,OUTPUT);
  27. pinMode(correctLED,OUTPUT);
  28. pinMode(wrongLED,OUTPUT);
  29. }
  30.  
  31. void loop() {
  32. byte counter = 0;
  33. char key = keypad.getKey();
  34. if(key != NO_KEY && key != &#039;#&#039; ) {
  35. blinkLED(keyLED);
  36. password.(key);
  37. counter++;
  38. }
  39.  
  40. if( key==&#039;#&#039;)
  41. {
  42. if(password.evaluate()) {
  43. blinkLED(correctLED);
  44. }
  45. else {
  46. blinkLED(wrongLED);
  47. }
  48. password.reset();
  49. }
  50. }
  51.  
  52. void blinkLED(byte ledPin) {
  53. digitalWrite(ledPin,HIGH);
  54. delay(200);
  55. digitalWrite(ledPin,LOW);
  56. }
Add Comment
Please, Sign In to add comment