123456789101112131415161718192021222324252627282930313233343536373839404142 |
- import RPi.GPIO as GPIO
- import time
- from lib.mqtt import create_client, control_player, create_config
- client = create_client()
- create_config(client)
- BUTTON_PINS = [17, 18, 27]
- GPIO.setmode(GPIO.BCM)
- for pin in BUTTON_PINS:
- GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
- def button_callback_1(channel):
- print("Button 1 pressed!")
- control_player(client, "PLAY")
- def button_callback_2(channel):
- print("Button 2 pressed!")
- control_player(client, "PAUSE")
- def button_callback_3(channel):
- print("Button 3 pressed!")
- GPIO.add_event_detect(BUTTON_PINS[0], GPIO.FALLING, callback=button_callback_1, bouncetime=200)
- GPIO.add_event_detect(BUTTON_PINS[1], GPIO.FALLING, callback=button_callback_2, bouncetime=200)
- GPIO.add_event_detect(BUTTON_PINS[2], GPIO.FALLING, callback=button_callback_3, bouncetime=200)
- try:
-
- while True:
- time.sleep(1)
- except KeyboardInterrupt:
- pass
- finally:
- GPIO.cleanup()
|