All pastes #3109312 Raw Edit

Untitled

public unlisted text v1 · immutable
#3109312 ·published 2015-08-16 18:24 UTC
rendered paste body
import RPi.GPIO as GPIO
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"
    sudo shutdown now -h
except KeyboardInterrupt:
    GPIO.cleanup()
GPIO.cleanup()