from keypad import Keypad
from machine import Pin
secretCode = '24861305'
isLocked = False
inbuffer = "________"
print("State = UNLOCKED")
def keyPressed(keyValue):
global isLocked, inbuffer
if isLocked:
if keyValue == '#':
if inbuffer == secretCode:
isLocked = False
print(" - Correct, State = UNLOCKED")
else:
print(" - Incorrect code.")
inbuffer = "________"
else:
inbuffer = inbuffer[1:] + keyValue
print(keyValue, end="")
elif keyValue == '*':
isLocked = True
print("State = LOCKED")
kp = Keypad(rows = (Pin(26), Pin(22), Pin(21), Pin(20)),
columns = (Pin(19), Pin(18), Pin(17), Pin(16)),
callback = keyPressed)