added basic volumen control

Signed-off-by: Ebbe Baß <ebbe@ping-mee.de>
master
Ebbe Baß 2022-04-26 21:33:41 +02:00
parent b3f36c1d1f
commit 65fee42217
2 changed files with 57 additions and 24 deletions

28
boot.py
View File

@ -1,16 +1,16 @@
from board import * # from board import *
import digitalio # import digitalio
import storage # import storage
noStorageStatus = False # noStorageStatus = False
noStoragePin = digitalio.DigitalInOut(GP0) # noStoragePin = digitalio.DigitalInOut(GP0)
noStoragePin.switch_to_input(pull=digitalio.Pull.UP) # noStoragePin.switch_to_input(pull=digitalio.Pull.UP)
noStorageStatus = not noStoragePin.value # noStorageStatus = not noStoragePin.value
if(noStorageStatus == False): # if(noStorageStatus == False):
# don't show USB drive to host PC # # don't show USB drive to host PC
storage.disable_usb_drive() # storage.disable_usb_drive()
print("Disabling USB drive") # print("Disabling USB drive")
else: # else:
# normal boot # # normal boot
print("USB drive enabled") # print("USB drive enabled")

47
code.py
View File

@ -4,6 +4,7 @@ import time
import usb_hid import usb_hid
from adafruit_hid.consumer_control_code import ConsumerControlCode from adafruit_hid.consumer_control_code import ConsumerControlCode
from adafruit_hid.consumer_control import ConsumerControl from adafruit_hid.consumer_control import ConsumerControl
from adafruit_hid.mouse import Mouse
clkPin = digitalio.DigitalInOut(board.GP2) clkPin = digitalio.DigitalInOut(board.GP2)
dtPin = digitalio.DigitalInOut(board.GP1) dtPin = digitalio.DigitalInOut(board.GP1)
@ -12,16 +13,48 @@ clkPin.direction = digitalio.Direction.INPUT
clkPin.pull = digitalio.Pull.UP clkPin.pull = digitalio.Pull.UP
dtPin.pull = digitalio.Pull.UP dtPin.pull = digitalio.Pull.UP
previousValue = True global buttonPin
buttonPin = digitalio.DigitalInOut(board.GP15)
buttonPin.direction = digitalio.Direction.INPUT
buttonPin.pull = digitalio.Pull.UP
global consumer_control
consumer_control = ConsumerControl(usb_hid.devices) consumer_control = ConsumerControl(usb_hid.devices)
while True: global mode
if previousValue != clkPin.value: mode = 0
if clkPin.value == False: global previousValue
if dtPin.value == False: previousValue = True
print('left')
def control_volumen(pinStatus):
if pinStatus == False:
print('Volumen down')
consumer_control.send(ConsumerControlCode.VOLUME_DECREMENT) consumer_control.send(ConsumerControlCode.VOLUME_DECREMENT)
else: else:
print('right') print('Volumen up')
consumer_control.send(ConsumerControlCode.VOLUME_INCREMENT) consumer_control.send(ConsumerControlCode.VOLUME_INCREMENT)
def mute_volumen():
consumer_control.send(ConsumerControlCode.MUTE)
print('Mute')
while True:
if buttonPin.value == False:
if mode == 0:
mute_volumen()
else:
mode = 0
mute_volumen()
print('Button pressed')
time.sleep(0.5)
else:
if previousValue != clkPin.value:
if clkPin.value == False:
if mode == 0:
control_volumen(dtPin.value)
else:
mode = 0
control_volumen(dtPin.value)
previousValue = clkPin.value previousValue = clkPin.value
print('Rotary Status: ' + str(clkPin.value))