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")

53
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)
global mode
mode = 0
global previousValue
previousValue = True
def control_volumen(pinStatus):
if pinStatus == False:
print('Volumen down')
consumer_control.send(ConsumerControlCode.VOLUME_DECREMENT)
else:
print('Volumen up')
consumer_control.send(ConsumerControlCode.VOLUME_INCREMENT)
def mute_volumen():
consumer_control.send(ConsumerControlCode.MUTE)
print('Mute')
while True: while True:
if previousValue != clkPin.value: if buttonPin.value == False:
if clkPin.value == False: if mode == 0:
if dtPin.value == False: mute_volumen()
print('left') else:
consumer_control.send(ConsumerControlCode.VOLUME_DECREMENT) mode = 0
else: mute_volumen()
print('right') print('Button pressed')
consumer_control.send(ConsumerControlCode.VOLUME_INCREMENT) time.sleep(0.5)
previousValue = clkPin.value 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
print('Rotary Status: ' + str(clkPin.value))