Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Keypad.h>
- #include <Wire.h>
- #include <LCD.h>
- #include <LiquidCrystal_I2C.h>
- #define I2C_ADDR 0x27 // Define I2C Address where the PCF8574A is
- #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
- LiquidCrystal_I2C lcd(I2C_ADDR, En_pin, Rw_pin, Rs_pin, D4_pin, D5_pin, D6_pin, D7_pin);
- const int beeper = 11;
- const byte ROWS = 4; //four rows
- const byte COLS = 4; //four columns
- char keys[ROWS][COLS] = {
- {'1', '2', '3', 'A'},
- {'4', '5', '6', 'B'},
- {'7', '8', '9', 'C'},
- {'*', '0', '#', 'D'}
- };
- byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
- byte colPins[COLS] = {9, 8, 7, 6}; //connect to the column pinouts of the keypad
- Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
- const String valid = "7A8C";
- String entry = "";
- void setup() {
- Serial.begin(9600);
- lcd.begin (20, 4);
- // Switch on the backlight
- lcd.setBacklightPin(BACKLIGHT_PIN, POSITIVE);
- lcd.setBacklight(HIGH);
- lcd.home();
- lcd.print(" SECU-SURE SECURITY");
- delay(2000);
- tone(beeper, 987);
- delay(100);
- tone(beeper, 1318);
- delay(300);
- noTone(beeper);
- lcd.setCursor ( 0, 1 );
- lcd.print(" >>>> SECURE <<<< ");
- }
- void loop() {
- char key = keypad.getKey();
- if (key) {
- tone(beeper, 3000);
- delay(50);
- noTone(beeper);
- Serial.print(key);
- if (entry.length() == 3) {
- delay(200);
- lcd.setCursor(7, 3);
- lcd.print("*");
- entry = entry + String(key);
- Serial.println("");
- lcd.setCursor ( 0, 3 );
- lcd.print(" ");
- if (entry == valid) {
- lcd.setCursor ( 0, 1 );
- lcd.print(" >>>> UNLOCK <<<< ");
- //do things
- tone(beeper, 3000);
- delay(50);
- noTone(beeper);
- delay(50);
- tone(beeper, 3000);
- delay(50);
- noTone(beeper);
- delay(5000);
- lcd.setCursor ( 0, 1 );
- lcd.print(" >>>> SECURE <<<< ");
- } else {
- tone(beeper, 400);
- delay(1500);
- noTone(beeper);
- }
- entry = "";
- }
- else if (entry.length() == 2) {
- lcd.setCursor(6, 3);
- lcd.print("*");
- entry = entry + String(key);
- }
- else if (entry.length() == 1) {
- lcd.setCursor(5, 3);
- lcd.print("*");
- entry = entry + String(key);
- }
- else if (entry.length() == 0) {
- lcd.setCursor(0, 3);
- lcd.print("PIN:");
- lcd.setCursor(4, 3);
- lcd.print("*");
- entry = String(key);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement