<gh_stars>1-10
# Bibliotheken und Klassen
from gpiozero import LED, Button
from gpiozero.pins.pigpio import PiGPIOFactory
from time import sleep

# GPIO der Status-LED
pin_status = 17
# GPIO des Tasters
pin_button = 25

status = True
led_blink = False

def stop_function():   # Callback Funktion zum Programm beenden
     global status
     status = False

def led_function():     # Callback Funktion für die LED (blinken/leuchten)
     global led_blink
     led_blink = not led_blink

# Initialisiere LED am GPIO-Pin 17
led = LED(pin_status)
# Initialisiere Button am GPIO-Pin 25
schalter = Button(pin_button, pull_up = True, hold_time = 2)
schalter.when_pressed = led_function
schalter.when_held = stop_function

# Try-Catch-Block
try:
    # Hauptschleife
    while status:
        if led_blink:
            led.off()
        else:
            led.on()
# Fangen eines Fehlers/Signals
except KeyboardInterrupt:
    print("Programm abgebrochen.")

# Bibliotheken und Klassen
from gpiozero import LED, Button
from gpiozero.pins.pigpio import PiGPIOFactory
from time import sleep

# GPIO der Status-LED
pin_status = 17
# GPIO des Tasters
pin_button = 25

status = True
led_blink = False

def stop_function():   # Callback Funktion zum Programm beenden
     global status
     status = False

def led_function():     # Callback Funktion für die LED (blinken/leuchten)
     global led_blink
     led_blink = not led_blink

# Initialisiere LED am GPIO-Pin 17
led = LED(pin_status)
# Initialisiere Button am GPIO-Pin 25
schalter = Button(pin_button, pull_up = True, hold_time = 2)
schalter.when_pressed = led_function
schalter.when_held = stop_function

# Try-Catch-Block
try:
    # Hauptschleife
    while status:
        if led_blink:
            led.off()
        else:
            led.on()
# Fangen eines Fehlers/Signals
except KeyboardInterrupt:
    print("Programm abgebrochen.")
# Bibliotheken und Klassen # GPIO der Status-LED # GPIO des Tasters # Callback Funktion zum Programm beenden # Callback Funktion für die LED (blinken/leuchten) # Initialisiere LED am GPIO-Pin 17 # Initialisiere Button am GPIO-Pin 25 # Try-Catch-Block # Hauptschleife # Fangen eines Fehlers/Signals