forked from gigafide/raspberrypi_spotify_radio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvolume.py
34 lines (29 loc) · 918 Bytes
/
volume.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/python
#Control MPD Client volume using a physical rotary encoder
#pip install mopidy-spotify
from RPi import GPIO
from time import sleep
import os
clk = 17
dt = 27
GPIO.setmode(GPIO.BCM)
GPIO.setup(clk, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(dt, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
counter = 0
clkLastState = GPIO.input(clk)
currVolume = 50
try:
while True:
clkState = GPIO.input(clk)
dtState = GPIO.input(dt)
if clkState != clkLastState:
if dtState != clkState:
currVolume += 5
else:
currVolume -= 5
# print currVolume
os.system("mpc volume " + str(currVolume))
clkLastState = clkState
sleep(0.01)
finally:
GPIO.cleanup