This repository has been archived on 2024-12-15. You can view files and clone it, but cannot push or open issues or pull requests.
Pi/button_led.py

31 lines
674 B
Python
Raw Normal View History

#!/usr/bin/python
from time import sleep
import RPi.GPIO as GPIO
2015-12-31 13:11:37 +00:00
ledPin = 14
buttonPin = 16
def buttonHandler(channel):
print "button pushed"
GPIO.output(ledPin, not GPIO.input(ledPin))
try:
GPIO.setmode(GPIO.BCM)
2015-12-31 13:11:37 +00:00
GPIO.setup(ledPin, GPIO.OUT)
GPIO.setup(buttonPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(15, GPIO.IN, pull_up_down=GPIO.PUD_UP)
2015-12-31 13:11:37 +00:00
GPIO.add_event_detect(buttonPin, GPIO.FALLING, callback=buttonHandler, bouncetime=300)
2015-12-31 13:11:37 +00:00
GPIO.output(ledPin, False)
while True:
2015-12-31 13:11:37 +00:00
GPIO.wait_for_edge(15, GPIO.RISING)
print "blah"
except KeyboardInterrupt:
2015-12-31 13:11:37 +00:00
GPIO.output(ledPin, False)
finally:
GPIO.cleanup()