Skip to content

add with as method #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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)