callback test buttons
This commit is contained in:
@@ -0,0 +1,42 @@
|
|||||||
|
import RPi.GPIO as GPIO
|
||||||
|
import time
|
||||||
|
from threading import Thread
|
||||||
|
|
||||||
|
# Buttons on PINs 9, 10 and 11
|
||||||
|
PIN_PREV = 10
|
||||||
|
PIN_PLAY = 9
|
||||||
|
PIN_NEXT = 11
|
||||||
|
|
||||||
|
GPIO.setmode(GPIO.BCM)
|
||||||
|
GPIO.setup(PIN_PREV, GPIO.IN, pull_up_down=GPIO.PUD_UP)
|
||||||
|
GPIO.setup(PIN_PLAY, GPIO.IN, pull_up_down=GPIO.PUD_UP)
|
||||||
|
GPIO.setup(PIN_NEXT, GPIO.IN, pull_up_down=GPIO.PUD_UP)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def prev_callback(channel):
|
||||||
|
print('Button 1 (PREV)')
|
||||||
|
|
||||||
|
def play_callback(channel):
|
||||||
|
print('Button 2 (PLAY/PAUSE)')
|
||||||
|
|
||||||
|
def next_callback(channel):
|
||||||
|
print('Button 3 (NEXT)')
|
||||||
|
|
||||||
|
|
||||||
|
GPIO.add_event_detect(PIN_PREV, GPIO.RISING, callback=prev_callback, bouncetime=200)
|
||||||
|
GPIO.add_event_detect(PIN_PLAY, GPIO.RISING, callback=play_callback, bouncetime=200)
|
||||||
|
GPIO.add_event_detect(PIN_NEXT, GPIO.RISING, callback=next_callback, bouncetime=200)
|
||||||
|
|
||||||
|
try:
|
||||||
|
|
||||||
|
while True:
|
||||||
|
time.sleep(0.01)
|
||||||
|
|
||||||
|
|
||||||
|
# Exit when Ctrl-C is pressed
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print('Shutdown')
|
||||||
|
finally:
|
||||||
|
GPIO.cleanup()
|
||||||
|
|
||||||
Reference in New Issue
Block a user