Created
June 25, 2013 02:13
-
-
Save stw/5855392 to your computer and use it in GitHub Desktop.
Simple RPi toggle switch
This file contains 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
import RPi.GPIO as GPIO | |
GPIO.setmode(GPIO.BCM) | |
push_button = 17 | |
led = 22 | |
GPIO.setup(push_button, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) | |
GPIO.setup(led, GPIO.OUT) | |
last = False | |
def notify(channel): | |
global last | |
print "Notify!" | |
print channel | |
if last == False: | |
GPIO.output(led, False) | |
last = True | |
else: | |
GPIO.output(led, True) | |
last = False | |
GPIO.add_event_detect(push_button, GPIO.FALLING, callback=notify, bouncetime=200) | |
raw_input("Push key to exit") | |
GPIO.cleanup() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment