01-07-2021, 04:56 AM
I built a headless music player for the bedroom [will post details later] and wanted to illuminate the volume dial when the player was on. I used lcdup.py to control the GPIO to drive the LED. You can also use this to indicate the status of random / repeat on the player.
here is the script I used
import RPi.GPIO as GPIO
import time;
import os;
import subprocess;
# Use SoC pin numbering
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(27, GPIO.OUT)
with open("/var/local/www/currentsong.txt") as file1:
with open("/home/pi/lcd.txt", "w") as file2:
for line in file1:
file2.write(line)
cmd1 = "mpc | head -2 | tail -1 | awk '{print $1}'"
process = subprocess.Popen(cmd1, stdout=subprocess.PIPE , shell=True)
os.waitpid(process.pid, 0)[1]
mpc_state = process.stdout.read().strip()
if mpc_state == "[playing]":
GPIO.output(27,1)
else:
GPIO.output(27,0)
here is the script I used
import RPi.GPIO as GPIO
import time;
import os;
import subprocess;
# Use SoC pin numbering
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(27, GPIO.OUT)
with open("/var/local/www/currentsong.txt") as file1:
with open("/home/pi/lcd.txt", "w") as file2:
for line in file1:
file2.write(line)
cmd1 = "mpc | head -2 | tail -1 | awk '{print $1}'"
process = subprocess.Popen(cmd1, stdout=subprocess.PIPE , shell=True)
os.waitpid(process.pid, 0)[1]
mpc_state = process.stdout.read().strip()
if mpc_state == "[playing]":
GPIO.output(27,1)
else:
GPIO.output(27,0)