#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
char keys[4][4] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}};
byte rowPins[4] = {7,6,5,4}; 
byte colPins[4] = {3,2,1,0}; 
char num[4];
int m=3;
Keypad keypad = Keypad(makeKeymap(keys),rowPins,colPins,4,4);
void setup()
{
  lcd.begin();
  lcd.setCursor(0,0);
  lcd.print("PW : ");
  lcd.setCursor(5,0);
  lcd.cursor();
}
void loop()
{  
  char key = keypad.getKey();
  if ((key != NO_KEY) && (key>=48) && (key<=57))
  {
    lcd.print(key);
    num[m]=key;
    m--;
    if(m<0)
    {
      delay(500);
      lcd.setCursor(0,1);
      if((num[3]=='4')&&(num[2]=='5')&&(num[1]=='9')&&(num[0]=='6'))
      {
        lcd.print("OPEN");
      }
      else
      {             
        lcd.print("CLOSE");
      }      
      delay(1500);      
      m=3;
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("PW : ");
      lcd.setCursor(5,0);  
     }
   }
}


