2015-12-23 21:24:22 +00:00
|
|
|
#!/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):
|
|
|
|
GPIO.output(ledPin, not GPIO.input(ledPin))
|
|
|
|
|
2015-12-23 21:24:22 +00:00
|
|
|
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-23 21:24:22 +00:00
|
|
|
|
2015-12-31 13:11:37 +00:00
|
|
|
GPIO.add_event_detect(buttonPin, GPIO.FALLING, callback=buttonHandler, bouncetime=300)
|
2015-12-23 21:24:22 +00:00
|
|
|
|
2015-12-31 13:11:37 +00:00
|
|
|
GPIO.output(ledPin, False)
|
|
|
|
|
2015-12-23 21:24:22 +00:00
|
|
|
while True:
|
2015-12-31 13:11:37 +00:00
|
|
|
GPIO.wait_for_edge(15, GPIO.RISING)
|
2015-12-23 21:24:22 +00:00
|
|
|
except KeyboardInterrupt:
|
2016-02-01 07:55:27 +00:00
|
|
|
pass
|
2015-12-23 21:24:22 +00:00
|
|
|
finally:
|
|
|
|
GPIO.cleanup()
|