From f75c95d141a1c9d3084d704b8e099ca73138e645 Mon Sep 17 00:00:00 2001 From: Karl Date: Mon, 8 Nov 2021 12:11:09 +0000 Subject: [PATCH] working button logic --- buttons.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 buttons.py diff --git a/buttons.py b/buttons.py new file mode 100644 index 0000000..3f666c3 --- /dev/null +++ b/buttons.py @@ -0,0 +1,48 @@ +import RPi.GPIO as GPIO +import time +import subprocess + +GPIO.setmode(GPIO.BCM) + +GPIO.setup(14, GPIO.IN, pull_up_down=GPIO.PUD_UP) +GPIO.setup(15, GPIO.IN, pull_up_down=GPIO.PUD_UP) +GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_UP) +GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_UP) + +while True: + input_state = GPIO.input(14) + if input_state == False: + print('playpause') + result = subprocess.run( + [f"python ./player.py playpause"], + stdout=subprocess.PIPE, + shell=True, + ).stdout.decode("utf-8") + time.sleep(0.2) + input_state = GPIO.input(15) + if input_state == False: + print('next') + result = subprocess.run( + [f"python ./player.py next"], + stdout=subprocess.PIPE, + shell=True, + ).stdout.decode("utf-8") + time.sleep(0.2) + input_state = GPIO.input(24) + if input_state == False: + print('previous') + result = subprocess.run( + [f"python ./player.py previous"], + stdout=subprocess.PIPE, + shell=True, + ).stdout.decode("utf-8") + time.sleep(0.2) + input_state = GPIO.input(23) + if input_state == False: + print('shuffle') + result = subprocess.run( + [f"python ./player.py shuffle"], + stdout=subprocess.PIPE, + shell=True, + ).stdout.decode("utf-8") + time.sleep(0.2)