Thank you for your donation!


Cloudsmith graciously provides open-source package management and distribution for our project.


Solved: LED indicator to show when music is playing
#9
Success!

So here's how I adapted Macdelf's script to my needs:

I have an LED light mounted on the front panel of my enclosure. This LED is connected to GND and to GPIO13 which was used as an activity status indicator. For that to work I added the following to /boot/config.txt:
Code:
#Use LED as SD indicator on GPIO 13
dtoverlay=pi3-act-led,gpio=13

Using Macdelf script made the status light (front panel) go off, and the power light go on when music was playing, so I simply inverted the behaviour of the script (echo 1 and echo 0) as following:
Code:
import os 
import subprocess
import time
                                                                                                                                                                                                           
#os.system("sudo sh -c 'echo none > /sys/class/leds/led0/trigger'")
#os.system("sudo sh -c 'echo none > /sys/class/leds/led1/trigger'")
                                                                                                                                                                                                           
while True:
        output = subprocess.getoutput(["mpc -w status"])
        if "[playing]" in output:
                os.system("sudo sh -c 'echo 1 > /sys/class/leds/led0/brightness'")
                os.system("sudo sh -c 'echo 0 > /sys/class/leds/led1/brightness'")
                os.system("mpc -q -w idle")
                                                                                                                                                                                                           
        else:
                if "[paused]" in output:
                        os.system("sudo sh -c 'echo 0 > /sys/class/leds/led1/brightness'")
                        os.system("sudo sh -c 'echo 0 > /sys/class/leds/led0/brightness'")
                        os.system("mpc -q -w idle")
                else:
                        os.system("sudo sh -c 'echo 0 > /sys/class/leds/led1/brightness'")
                        os.system("sudo sh -c 'echo 0 > /sys/class/leds/led0/brightness'")
                        os.system("mpc -q -w idle")
Now when music is playing the pilot light on the front panel will light up exactly as I wanted it to do. 

Thanks again to all of you for the help!
Reply


Messages In This Thread
RE: LED indicator to show when music is playing - by seipersei - 02-22-2022, 10:41 PM

Forum Jump: