12.05.2019, 14:11
ah ok da könnte ja der fehler liegen.
die Belegung sieht so aus GPIO 5 (Pin 29)
CLK
GPIO 6 (Pin 31)
DT
GPIO 13 (Pin 33)
SW
3.3V (Pin 1)
+
GND (Pin 6)
GND
dann habe ich folgende Bibliothek geladen https://github.com/conradstorz/KY040
und dann in cd KY040
sudo nano volume_regulator.py
folgendes eingefügt
import RPi.GPIO as GPIO
from KY040 import KY040
import os, time
def readVolume():
value = os.popen("amixer get PCM|grep -o [0-9]*%|sed 's/%//'").read()
return int(value)
def rotaryChange(direction):
volume_step = 5
volume = readVolume()
if direction == 1:
os.system("sudo amixer set PCM -- "+str(min(100,max(0,volume + volume_step)))+"%")
else:
os.system("sudo amixer set PCM -- "+str(min(100,max(0,volume - volume_step)))+"%")
def switchPressed():
print "button pressed"
if __name__ == "__main__":
CLOCKPIN = 5
DATAPIN = 6
SWITCHPIN = 13
GPIO.setmode(GPIO.BCM)
ky040 = KY040(CLOCKPIN, DATAPIN, SWITCHPIN, rotaryChange, switchPressed)
ky040.start()
try:
while True:
time.sleep(0.05)
finally:
ky040.stop()
GPIO.cleanup()
die Belegung sieht so aus GPIO 5 (Pin 29)
CLK
GPIO 6 (Pin 31)
DT
GPIO 13 (Pin 33)
SW
3.3V (Pin 1)
+
GND (Pin 6)
GND
dann habe ich folgende Bibliothek geladen https://github.com/conradstorz/KY040
und dann in cd KY040
sudo nano volume_regulator.py
folgendes eingefügt
import RPi.GPIO as GPIO
from KY040 import KY040
import os, time
def readVolume():
value = os.popen("amixer get PCM|grep -o [0-9]*%|sed 's/%//'").read()
return int(value)
def rotaryChange(direction):
volume_step = 5
volume = readVolume()
if direction == 1:
os.system("sudo amixer set PCM -- "+str(min(100,max(0,volume + volume_step)))+"%")
else:
os.system("sudo amixer set PCM -- "+str(min(100,max(0,volume - volume_step)))+"%")
def switchPressed():
print "button pressed"
if __name__ == "__main__":
CLOCKPIN = 5
DATAPIN = 6
SWITCHPIN = 13
GPIO.setmode(GPIO.BCM)
ky040 = KY040(CLOCKPIN, DATAPIN, SWITCHPIN, rotaryChange, switchPressed)
ky040.start()
try:
while True:
time.sleep(0.05)
finally:
ky040.stop()
GPIO.cleanup()