This commit is contained in:
JonOfUs 2024-08-21 14:36:59 +02:00
parent fcca0c4972
commit a595f07038

26
main.py
View file

@ -28,6 +28,9 @@ button_pin = 18
toggle_switch_left_pin = 15
toggle_switch_right_pin = 14
# Cleanup GPIO to avoid "channel already in use" errors
GPIO.cleanup()
GPIO.setmode(GPIO.BCM)
GPIO.setup(button_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(toggle_switch_left_pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
@ -237,4 +240,25 @@ def button_pressed(channel):
animation_NR = (animation_NR + 1) % anzahl_animationen
reset_animation = True
GPIO.add_event_detect
GPIO.add_event_detect(button_pin, GPIO.FALLING, callback=button_pressed, bouncetime=200)
# Ensure GPIO cleanup on exit
import atexit
atexit.register(GPIO.cleanup)
# Main loop
try:
while True:
if animation_NR == 0:
licht_aus()
elif animation_NR == 1:
fernlicht_an()
elif animation_NR == 2:
rainbow()
elif animation_NR == 3:
police()
elif animation_NR == 4:
kit()
time.sleep(0.1)
except KeyboardInterrupt:
GPIO.cleanup()