I’d like to add physical pushbuttons for previous track, stop and next track. I hooked up some retro buttons to GPIO pins 2, 3 and 4, and the other sides to ground. I adapted some code below that does print out each of the three messages.
How do I architect this in to Mycroft to send those three commands?
Any help will be appreciated.
#!/usr/bin/env python3
import signal
import sys
import RPi.GPIO as GPIO
BUTTON_GPIO_2 = 2 # previous track
BUTTON_GPIO_3 = 3 # stop
BUTTON_GPIO_4 = 4 # next track
def signal_handler(sig, frame):
GPIO.cleanup()
sys.exit(0)
def button_pressed_callback(channel):
match channel:
case 2:
print("Previous track button pressed!")
case 3:
print("Stop button pressed!")
case 4:
print("Next track button pressed!")
if __name__ == '__main__':
GPIO.setmode(GPIO.BCM)
GPIO.setup(BUTTON_GPIO_2, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(BUTTON_GPIO_3, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(BUTTON_GPIO_4, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.add_event_detect(BUTTON_GPIO_2, GPIO.FALLING, callback=button_pressed_callback, bouncetime=100)
GPIO.add_event_detect(BUTTON_GPIO_3, GPIO.FALLING, callback=button_pressed_callback, bouncetime=100)
GPIO.add_event_detect(BUTTON_GPIO_4, GPIO.FALLING, callback=button_pressed_callback, bouncetime=100)
signal.signal(signal.SIGINT, signal_handler)
signal.pause()
Picture of the buttons: