Skip to content

Instantly share code, notes, and snippets.

@thecodingwizard
Created March 25, 2015 01:35
Show Gist options
  • Select an option

  • Save thecodingwizard/0adacf8b0a164491498f to your computer and use it in GitHub Desktop.

Select an option

Save thecodingwizard/0adacf8b0a164491498f to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
led_pin = 5
button_pin = 6
is_led_on = False
GPIO.setup(led_pin, GPIO.OUT)
GPIO.setup(button_pin, GPIO.IN)
def buttonPressed(channel):
print "Button pressed with GPIO number: " + channel
if is_led_on:
GPIO.output(led_pin, GPIO.LOW)
else:
GPIO.output(led_pin, GPIO.HIGH)
GPIO.add_event_detect(button_pin, GPIO.RISING, callback = buttonPressed, bouncetime = 300)
# make the application sleep forever so that it does not exit
while True:
time.sleep(100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment