At volume 100 everything is OK now, all LEDs are on.
But still: at volume 8 three LEDs are on, as if it would be between 75 and 87.
Maybe it's a python vs. python2 thing?
I am really curious about what's wrong here!
That's my current script and wiring diagramm for the volume LEDs (see attachment):
- Code: Select all
#!/usr/bin/env python2
# LED_volume.py
# IMPORTS
import sys
import time
# import os
import RPi.GPIO as GPIO
from mpd import (MPDClient)
#GPIO Setup
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
LED1 = 05
LED2 = 06
LED3 = 12
LED4 = 13
GPIO.setup(LED1,GPIO.OUT, initial=GPIO.LOW) #1st LED
GPIO.setup(LED2,GPIO.OUT, initial=GPIO.LOW) #2nd LED
GPIO.setup(LED3,GPIO.OUT, initial=GPIO.LOW) #3rd LED
GPIO.setup(LED4,GPIO.OUT, initial=GPIO.LOW) #4th LED
#definitions
client = MPDClient()
client.connect('localhost', 6600)
# Poll the volumelevel and set GPIO.output accordingly
while True:
status = client.status()
volume = status['volume']
if status['volume'] > '0': # 1st LED
GPIO.output(LED1,GPIO.HIGH)
print('volume = ' + str(volume))
else:
GPIO.output(LED1,GPIO.LOW)
print('MUTE')
if status['volume'] > '50': # 2nd LED
GPIO.output(LED2,GPIO.HIGH)
print('volume = ' + str(volume))
else:
GPIO.output(LED2,GPIO.LOW)
if status['volume'] > '75': # 3rd LED
GPIO.output(LED3,GPIO.HIGH)
print('volume = ' + str(volume))
else:
GPIO.output(LED3,GPIO.LOW)
if status['volume'] > '87': # 4th LED
GPIO.output(LED4,GPIO.HIGH)
print('volume = ' + str(volume))
else:
GPIO.output(LED4,GPIO.LOW)
if status['volume'] == '100': # ALL LEDs
GPIO.output(LED1,GPIO.HIGH)
GPIO.output(LED2,GPIO.HIGH)
GPIO.output(LED3,GPIO.HIGH)
GPIO.output(LED4,GPIO.HIGH)
print('volume = ' + str(volume))
time.sleep(0.2) # Delay loop for 0.2 second
# disconnect
client.disconnect()
# end of programm