from machine import Pin , I2C
from time import sleep
from esp32_i2c_lcd import I2cLcd
lcdI2C = I2C(scl = Pin(22), sda = Pin(21), freq = 100000)
print(lcdI2C.scan())
lcd = I2cLcd(lcdI2C,0x27,2,16)
lcd.clear()
rowPins = ( Pin(13,Pin.OUT),
Pin(12,Pin.OUT),
Pin(14,Pin.OUT),
Pin(27,Pin.OUT))
colPins = ( Pin(26,Pin.IN,Pin.PULL_DOWN),
Pin(25,Pin.IN,Pin.PULL_DOWN),
Pin(33,Pin.IN,Pin.PULL_DOWN),
Pin(32,Pin.IN,Pin.PULL_DOWN))
def getpad():
numPad = ( (1,2,3,4),
(5,6,7,8),
(9,10,11,12),
(13,14,15,16) )
for r in range(4):
for row in rowPins:
row.value(0)
rowPins[r].value(1)
for c in range(4):
if colPins[c].value() == 1:
return numPad[r][c]
return -1
lcd.putstr("Password: ")
password = "1234"
Key_Input = ""
while True:
KeyPad = getpad()
if KeyPad >= 0:
Key_Input += str(KeyPad)
lcd.clear()
lcd.putstr("Password: " + Key_Input)
if len(Key_Input) == 4:
if Key_Input == password:
lcd.clear()
lcd.putstr("pw is correct.\n")
lcd.putstr(" GODD LUCK")
break
else:
lcd.clear()
lcd.putstr("pw is incorrect.\n")
lcd.putstr("please try again")
sleep(3)
Key_Input = ""
lcd.clear()
lcd.putstr("Password: ")
sleep(0.1)