Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Password.h>
- #include <Wire.h>
- #include <LCD.h>
- #include <LiquidCrystal.h>
- #include <LiquidCrystal_I2C.h>
- #include <LiquidCrystal_SI2C.h>
- #include <Keypad.h>
- #include <Servo.h>
- int greenLight = 11;
- int redLight = 12;
- int servoPin = 3;
- int amount1 = 0;
- char pass[5];
- char realPass[5] = "2601";
- #define int servoPin = 13;
- #define I2C_ADDR 0x27
- #define BACKLIGHT_PIN 3
- #define En_pin 2
- #define Rw_pin 1
- #define Rs_pin 0
- #define D4_pin 4
- #define D5_pin 5
- #define D6_pin 6
- #define D7_pin 7
- const byte rows = 4; //four rows
- const byte cols = 4; //three columns
- char keys[rows][cols] = {
- {'1','2','3', 'A'},
- {'4','5','6', 'B'},
- {'7','8','9', 'C'},
- {'*','0','#', 'D'}
- };
- byte rowPins[rows] = {9,8,7,6}; //connect to the row pinouts of the keypad
- byte colPins[cols] = {5,4,3,2}; //connect to the column pinouts of the keypad
- Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, rows, cols );
- Servo Servo1;
- LiquidCrystal_I2C lcd(I2C_ADDR, En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
- void setup()
- {
- lcd.begin(16,2);
- Serial.begin(9600);
- lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
- lcd.setBacklight(HIGH);
- Servo1.attach(servoPin);
- Servo1.write(0);
- }
- void loop()
- {
- char key = keypad.getKey();
- char dataDump[2];
- bool correct = true;
- lcd.setCursor(0, 0);
- lcd.print("Enter Password:");
- lcd.setCursor(0, 1);
- if(key != NO_KEY)
- {
- if(amount1 != 4)
- {
- pass[amount1] = key;
- amount1++;
- Serial.println(pass);
- lcd.setCursor(0,1);
- lcd.print(pass);
- }
- if(amount1 == 4)
- {
- delay(1000);
- amount1 = 0;
- for(int i = 0; i <= sizeof(realPass); i++)
- {
- if(pass[i] != realPass[i] && correct)
- {
- correct = false;
- }
- else
- {
- correct = true;
- }
- }
- if(correct)
- {
- memset(pass, 0, sizeof(pass));
- lcd.setCursor(0,0);
- lcd.print("Correct! ");
- digitalWrite(greenLight, HIGH);
- delay(1500);
- digitalWrite(greenLight, LOW);
- }
- else
- {
- memset(pass, 0, sizeof(pass));
- lcd.setCursor(0,0);
- lcd.print("Incorrect! ");
- lcd.setCursor(0,1);
- lcd.print(" ");
- digitalWrite(redLight, HIGH);
- delay(1500);
- digitalWrite(redLight, LOW);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement