buttons.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import RPi.GPIO as GPIO
  2. import time
  3. import subprocess
  4. GPIO.setmode(GPIO.BCM)
  5. GPIO.setup(14, GPIO.IN, pull_up_down=GPIO.PUD_UP)
  6. GPIO.setup(15, GPIO.IN, pull_up_down=GPIO.PUD_UP)
  7. GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_UP)
  8. GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_UP)
  9. while True:
  10. input_state = GPIO.input(14)
  11. if input_state == False:
  12. print('playpause')
  13. result = subprocess.run(
  14. [f"python ./player.py playpause"],
  15. stdout=subprocess.PIPE,
  16. shell=True,
  17. ).stdout.decode("utf-8")
  18. time.sleep(0.2)
  19. input_state = GPIO.input(15)
  20. if input_state == False:
  21. print('next')
  22. result = subprocess.run(
  23. [f"python ./player.py next"],
  24. stdout=subprocess.PIPE,
  25. shell=True,
  26. ).stdout.decode("utf-8")
  27. time.sleep(0.2)
  28. input_state = GPIO.input(24)
  29. if input_state == False:
  30. print('previous')
  31. result = subprocess.run(
  32. [f"python ./player.py previous"],
  33. stdout=subprocess.PIPE,
  34. shell=True,
  35. ).stdout.decode("utf-8")
  36. time.sleep(0.2)
  37. input_state = GPIO.input(23)
  38. if input_state == False:
  39. print('shuffle')
  40. result = subprocess.run(
  41. [f"python ./player.py shuffle"],
  42. stdout=subprocess.PIPE,
  43. shell=True,
  44. ).stdout.decode("utf-8")
  45. time.sleep(0.2)