04-16-2018, 03:32 PM
Here's a simple example of how you can use a button connected on GPIO(4) to pause/play a song. I use this as part of the script that drives a 128x128 OLED display.
Code:
import subprocess
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(4, GPIO.IN, pull_up_down=GPIO.PUD_UP)
def mpdToggle():
status = subprocess.check_output(['mpc', 'toggle'])
def main():
while True:
input_state = GPIO.input(4)
if input_state == False:
mpdToggle()
time.sleep(pauseTime)