Untitled
unknown
plain_text
2 years ago
1.0 kB
7
Indexable
import RPi.GPIO as GPIO
import time
# Définir les numéros de broches
LED_PIN = 17 # Utilisez le numéro de broche GPIO approprié pour votre configuration
BUTTON_PIN = 18 # Utilisez le numéro de broche GPIO approprié pour votre configuration
def setup():
GPIO.setmode(GPIO.BCM)
GPIO.setup(LED_PIN, GPIO.OUT)
GPIO.setup(BUTTON_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)
def loop():
try:
while True:
button_state = GPIO.input(BUTTON_PIN)
if button_state == GPIO.LOW:
print("Bouton pressé - Allumer la LED")
GPIO.output(LED_PIN, GPIO.HIGH) # Allumer la LED
else:
GPIO.output(LED_PIN, GPIO.LOW) # Éteindre la LED
except KeyboardInterrupt:
pass
def destroy():
GPIO.output(LED_PIN, GPIO.LOW) # Assurez-vous que la LED est éteinte lors de la fermeture
GPIO.cleanup()
if __name__ == '__main__':
setup()
try:
loop()
except KeyboardInterrupt:
destroy()
Editor is loading...
Leave a Comment