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;
- #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();
- String pass = "";
- String realPass = "2601";
- lcd.setCursor(0, 0);
- lcd.print("Enter Password:");
- lcd.setCursor(0, 1);
- if(key != NO_KEY)
- {
- if(amount1 >= 4)
- {
- amount1 = 0;
- if(pass == realPass)
- {
- strcpy(pass, "");
- digitalWrite(greenLight, HIGH);
- delay(1500);
- digitalWrite(greenLight, LOW);
- }
- else
- {
- pass = "";
- lcd.setCursor(0,0);
- lcd.print("Correct!");
- lcd.setCursor(0,1);
- lcd.print("");
- digitalWrite(redLight, HIGH);
- delay(1500);
- digitalWrite(redLight, LOW);
- }
- }
- else
- {
- Serial.println(key);
- amount1++;
- oass = pass + key;
- lcd.setCursor(0,1);
- lcd.print(pass);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement