Fix
This commit is contained in:
parent
fcca0c4972
commit
a595f07038
1 changed files with 25 additions and 1 deletions
26
main.py
26
main.py
|
@ -28,6 +28,9 @@ button_pin = 18
|
||||||
toggle_switch_left_pin = 15
|
toggle_switch_left_pin = 15
|
||||||
toggle_switch_right_pin = 14
|
toggle_switch_right_pin = 14
|
||||||
|
|
||||||
|
# Cleanup GPIO to avoid "channel already in use" errors
|
||||||
|
GPIO.cleanup()
|
||||||
|
|
||||||
GPIO.setmode(GPIO.BCM)
|
GPIO.setmode(GPIO.BCM)
|
||||||
GPIO.setup(button_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
|
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)
|
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
|
animation_NR = (animation_NR + 1) % anzahl_animationen
|
||||||
reset_animation = True
|
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()
|
Loading…
Reference in a new issue