Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions 02_2-led_blink/led_blink.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,19 @@
GPIO.setmode(GPIO.BOARD)
GPIO.setup(LED_PIN, GPIO.OUT)

try:
class control_GPIO:
def __enter__(self):
pass
def __exit__(self,type, value, trace):
print("Exception: KeyboardInterrupt")
GPIO.cleanup()

with control_GPIO():
while True:
print("LED is on")
GPIO.output(LED_PIN, GPIO.HIGH)
time.sleep(1)

print("LED is off")
GPIO.output(LED_PIN, GPIO.LOW)
time.sleep(1)

except KeyboardInterrupt:
print("Exception: KeyboardInterrupt")

finally:
GPIO.cleanup()
time.sleep(1)