Created
December 28, 2013 17:34
-
-
Save lmullen/8161882 to your computer and use it in GitHub Desktop.
Blink an LED connected to a Raspberry Pi, and interrupt it with the keyboard
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# encoding: utf-8 | |
import time | |
import _thread | |
import RPi.GPIO as GPIO | |
GPIO.setmode(GPIO.BOARD) | |
GPIO.setup(11, GPIO.OUT) | |
def wait_for_input(stop): | |
input("Press enter to stop blinking.") | |
stop.append(True) | |
print("Stopping the blinking.") | |
def blink(): | |
stop = [] | |
_thread.start_new_thread(wait_for_input, (stop,)) | |
while True: | |
GPIO.output(11, True) | |
time.sleep(2) | |
GPIO.output(11, False) | |
time.sleep(2) | |
if stop: break | |
blink() | |
GPIO.cleanup() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Your saving my life with this code. Thanks!