Skip to content

Instantly share code, notes, and snippets.

@stw
Created June 25, 2013 02:13
Show Gist options
  • Save stw/5855392 to your computer and use it in GitHub Desktop.
Save stw/5855392 to your computer and use it in GitHub Desktop.
Simple RPi toggle switch
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