Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4923

General • Re: Ensuring PWM/GPIO outputs are low after critical events

$
0
0
run your code inside a try / except structure. As Ctrl-C raises an exception, as soon as it happens your code in the 'except:' part gets run:

Code:

try:    while True:        led.value(not led.value())        sleep_ms(1200)except:    led.value(0)  # turn it off if user quits    exit()
Any error at runtime that raises an exception will cause the code under 'except:' to be run

Statistics: Posted by scruss — Thu Feb 29, 2024 4:19 pm



Viewing all articles
Browse latest Browse all 4923

Trending Articles