from time import time, sleep
import RPi.GPIO as GPIO
from pad4pi import rpi_gpio
ROW_NUM = 4 # Nombre de rangées du clavier
COLUMN_NUM = 4 # Nombre de colonnes du clavier
password = "1234"
code = [""] * 4 # Tableau pour stocker le code saisi
chCode = ""
# Initialisation des broches du clavier matriciel
MATRIX = [["1", "2", "3", "A"],
["4", "5", "6", "B"],
["7", "8", "9", "C"],
["*", "0", "#", "D"]]
ROW_PINS = [32, 33, 25, 26]
COL_PINS = [27, 14, 12, 13]
# Initialisation des broches des LED
ledPinred = 2
ledPinyellow = 4
ledPingreen = 5
GPIO.setmode(GPIO.BCM)
# Configuration des broches des LED
GPIO.setup(ledPinred, GPIO.OUT)
GPIO.setup(ledPinyellow, GPIO.OUT)
GPIO.setup(ledPingreen, GPIO.OUT)
# Configuration du clavier
factory = rpi_gpio.KeypadFactory()
keypad = factory.create_keypad(keypad=GPIO, row_pins=ROW_PINS, col_pins=COL_PINS)
lcd = None # Ajoutez ici la configuration de votre écran LCD si nécessaire
def reset_code():
global code, chCode
code = [""] * 4
chCode = ""
# Effacez le code affiché sur l'écran LCD ici
def enter_code(key):
global code, chCode
code[i] = key
chCode += key
# Affichez le code saisi sur l'écran LCD ici
def authentication():
global code, chCode
while True:
event = keypad.get_event()
if event:
if event.direction == "down":
key = event.key
if key != "":
if key in ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "#", "*"]:
enter_code(key)
# Si le code est complet, comparez-le avec le mot de passe
if len(chCode) == 4:
if chCode == password:
print("Correct")
# Affichez "correct" sur l'écran LCD ici
break
else:
print("Incorrect code")
reset_code()
# Affichez "code incorrect" sur l'écran LCD ici
def codePANNE():
global code, chCode
while True:
# Affichez "code panne" sur l'écran LCD ici
event = keypad.get_event()
if event:
if event.direction == "down":
key = event.key
if key != "":
if key in ["A", "B", "C"]:
# Affichez la touche appuyée sur l'écran LCD ici
sleep(1)
if key == 'A':
GPIO.output(ledPinred, GPIO.HIGH)
print("Temps d'attente")
# Affichez "Temps d'attente" sur l'écran LCD ici
elif key == 'B':
GPIO.output(ledPinyellow, GPIO.HIGH)
print("Temps reparation")
# Affichez "Temps reparation" sur l'écran LCD ici
elif key == 'C':
GPIO.output(ledPingreen, GPIO.HIGH)
print("Machine en marche")
# Affichez "Machine en marche" sur l'écran LCD ici
break
else:
print("Incorrect code")
# Affichez "code panne incorrect" sur l'écran LCD ici
try:
authentication()
codePANNE()
finally:
GPIO.cleanup()
keypad.cleanup()