from machine import Pin
import time
# Keypad Layout 4x4
KEYS = [
['1', '2', '3', 'A'],
['4', '5', '6', 'B'],
['7', '8', '9', 'C'],
['*', '0', '#', 'D']
]
# GPIO-Pins (anpassen wenn nötig)
row_pins = [Pin(i, Pin.OUT) for i in (2, 3, 4, 5)]
col_pins = [Pin(i, Pin.IN, Pin.PULL_DOWN) for i in (6, 7, 8, 9)]
# Passwortliste (deine vorgegebenen Codes)
password_list = ["6737", "2468", "4561", "8197", "7452","8373"]
password_index = 0 # Start bei erstem Passwort
current_password = password_list[password_index]
input_password = ""
def scan_keypad():
global input_password, current_password, password_index
for row_idx, row in enumerate(row_pins):
row.high()
for col_idx, col in enumerate(col_pins):
if col.value():
key = KEYS[row_idx][col_idx]
print("Taste gedrückt:", key)
time.sleep(0.3)
if key == '#':
print("Eingabe abgeschlossen:", input_password)
if input_password == current_password:
print("Zugriff erlaubt für Passwort:", current_password)
password_index += 1
if password_index < len(password_list):
current_password = password_list[password_index]
print("Neues Passwort gesetzt:", current_password)
else:
print("Keine weiteren Passwörter – Ende der Liste!")
# Optional: stoppen oder Passwort wiederholen
password_index = 0
current_password = password_list[password_index]
print("Zurück zum ersten Passwort:", current_password)
else:
print("Falsches Passwort!")
input_password = ""
elif key == '*':
input_password = input_password[:-1]
print("Zeichen gelöscht")
elif key in '0123456789':
input_password += key
print("Eingabe:", input_password)
row.low()
# Startinfo
print("System bereit – aktuelles Passwort:", current_password)
# Hauptloop
while True:
scan_keypad()