Hi, I have a HifiBerry AMP and wonder if it is possible to control volume via GPIO?
What I need is:
Volume up
Volume down
Mute
Mute LED (Out)
EDIT:
This works accept the mute function (don’t know why).
And it also requires u to install extra packages…
#!/bin/python
from gpiozero import Button
from signal import pause
from subprocess import Popendef increase_volume():
Popen([‘amixer’, ‘-c’, ‘1’, ‘sset’, ‘Master’, ‘1+’, ‘-q’])def decrease_volume():
Popen([‘amixer’, ‘-c’, ‘1’, ‘sset’, ‘Master’, ‘1-’, ‘-q’])def mute_volume():
Popen([‘amixer’, ‘-c’, ‘1’, ‘sset’, ‘Master’, ‘toggle’, ‘-q’])button_up = Button(23, pull_up = False)
button_up.when_pressed = increase_volume
button_down = Button(24, pull_up = False)
button_down.when_pressed = decrease_volume
button_mute = Button(25, pull_up = False)
button_mute.when_held = mute_volumepause()