I am trying to build a locker with Raspberry Pi. I have a code that when entering a correct CODE = '1234' with USB keyboard it opens a servo. Basically it works, but need to loop it somehow so, if I put wrong PIN, I am asked again to put correct.
for event in dev.read_loop():
if event.type == ecodes.EV_KEY:
e = categorize(event)
if e.keystate == e.key_down:
klawisz = e.keycode[4:]
if klawisz != "ESC":
kod = (kod + klawisz)
print(kod)
else:
break
if kod == '1234':
for event in dev.read_loop():
if event.type == ecodes.EV_KEY:
d = categorize(event)
if d.keystate == d.key_down:
klawisz = d.keycode[4:]
if klawisz == "ESC":
print('ITS OPEN')
break
else:
break
else:
print('Wrong PIN')
I tried with while loop at the beginning, but it doesn't work :(
while kod == '1234'
Hope you could you guide me to correct solution, as I am still learning Python. Thanks.