rendered paste bodyimport RPi.GPIO as GPIO
import subprocess
GPIO.setmode(GPIO.BCM)
GPIO.setup(22, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(4, GPIO.IN, pull_up_down=GPIO.PUD_UP)
def my_callback(channel):
print "button pressed - falling edge detected on 22"
def my_callback2(channel):
print "button pressed - falling edge detected on 23"
def my_callback3(channel):
print "button pressed - falling edge detected on 24"
GPIO.add_event_detect(22, GPIO.FALLING, callback=my_callback, bouncetime=300)
GPIO.add_event_detect(23, GPIO.FALLING, callback=my_callback2, bouncetime=300)
GPIO.add_event_detect(24, GPIO.FALLING, callback=my_callback3, bouncetime=300)
try:
GPIO.wait_for_edge(4, GPIO.FALLING)
print "shutting down"
subprocess.call(["sudo", "halt"])
except KeyboardInterrupt:
GPIO.cleanup()
GPIO.cleanup()