Advertisement
Guest User

Arduino

a guest
Apr 1st, 2020
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. #include <Password.h>
  2.  
  3. #include <Wire.h>
  4. #include <LCD.h>
  5. #include <LiquidCrystal.h>
  6. #include <LiquidCrystal_I2C.h>
  7. #include <LiquidCrystal_SI2C.h>
  8.  
  9.  
  10. #include <Keypad.h>
  11. #include <Servo.h>
  12.  
  13. int greenLight = 11;
  14. int redLight = 12;
  15. int servoPin = 3;
  16. int amount1 = 0;
  17.  
  18. char pass[5];
  19. char realPass[5] = "2601";
  20.  
  21. #define int servoPin = 13;
  22. #define I2C_ADDR 0x27
  23. #define BACKLIGHT_PIN 3
  24. #define En_pin 2
  25. #define Rw_pin 1
  26. #define Rs_pin 0
  27. #define D4_pin 4
  28. #define D5_pin 5
  29. #define D6_pin 6
  30. #define D7_pin 7
  31.  
  32. const byte rows = 4; //four rows
  33. const byte cols = 4; //three columns
  34. char keys[rows][cols] = {
  35. {'1','2','3', 'A'},
  36. {'4','5','6', 'B'},
  37. {'7','8','9', 'C'},
  38. {'*','0','#', 'D'}
  39. };
  40.  
  41. byte rowPins[rows] = {9,8,7,6}; //connect to the row pinouts of the keypad
  42. byte colPins[cols] = {5,4,3,2}; //connect to the column pinouts of the keypad
  43. Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, rows, cols );
  44.  
  45. Servo Servo1;
  46.  
  47. LiquidCrystal_I2C lcd(I2C_ADDR, En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
  48.  
  49. void setup()
  50. {
  51. lcd.begin(16,2);
  52. Serial.begin(9600);
  53. lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
  54. lcd.setBacklight(HIGH);
  55. Servo1.attach(servoPin);
  56. Servo1.write(0);
  57. }
  58.  
  59.  
  60. void loop()
  61. {
  62. char key = keypad.getKey();
  63. char dataDump[2];
  64. bool correct = true;
  65.  
  66. lcd.setCursor(0, 0);
  67. lcd.print("Enter Password:");
  68. lcd.setCursor(0, 1);
  69.  
  70. if(key != NO_KEY)
  71. {
  72. if(amount1 != 4)
  73. {
  74. pass[amount1] = key;
  75. amount1++;
  76. Serial.println(pass);
  77. lcd.setCursor(0,1);
  78. lcd.print(pass);
  79. }
  80.  
  81. if(amount1 == 4)
  82. {
  83. delay(1000);
  84. amount1 = 0;
  85.  
  86.  
  87. for(int i = 0; i <= sizeof(realPass); i++)
  88. {
  89. if(pass[i] != realPass[i] && correct)
  90. {
  91. correct = false;
  92. }
  93. else
  94. {
  95. correct = true;
  96. }
  97. }
  98.  
  99. if(correct)
  100. {
  101. memset(pass, 0, sizeof(pass));
  102. lcd.setCursor(0,0);
  103. lcd.print("Correct! ");
  104. digitalWrite(greenLight, HIGH);
  105. delay(1500);
  106. digitalWrite(greenLight, LOW);
  107. }
  108. else
  109. {
  110. memset(pass, 0, sizeof(pass));
  111. lcd.setCursor(0,0);
  112. lcd.print("Incorrect! ");
  113. lcd.setCursor(0,1);
  114. lcd.print(" ");
  115. digitalWrite(redLight, HIGH);
  116. delay(1500);
  117. digitalWrite(redLight, LOW);
  118. }
  119. }
  120. }
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement