Skip to content

Instantly share code, notes, and snippets.

@Yi-Tseng
Created September 23, 2012 16:04
Show Gist options
  • Save Yi-Tseng/3772143 to your computer and use it in GitHub Desktop.
Save Yi-Tseng/3772143 to your computer and use it in GitHub Desktop.
from threading import Thread
import RPi.GPIO as GPIO
x = 0
def keyListen():
stat = False
global x
while 1:
if GPIO.input(11) and not stat:
stat = True
print "Hello!"
x = x+1
if not GPIO.input(11):
stat = False
def main():
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11,GPIO.IN)
#GPIO.setup(1,GPIO.OUT)
print "Running!"
t = Thread(target = keyListen,args=())
t.start()
while 1:
cmd = raw_input("Input command(times,LED):\n")
if cmd == "times":
print x
elif cmd == "LED":
print "Led"
else:
print "Error command!"
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment