From 65fee42217a192d090230a275bffd292955f5dba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ebbe=20Ba=C3=9F?= Date: Tue, 26 Apr 2022 21:33:41 +0200 Subject: [PATCH] added basic volumen control MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ebbe Baß --- boot.py | 28 ++++++++++++++-------------- code.py | 53 +++++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 57 insertions(+), 24 deletions(-) diff --git a/boot.py b/boot.py index ef788cb..42b0e1d 100644 --- a/boot.py +++ b/boot.py @@ -1,16 +1,16 @@ -from board import * -import digitalio -import storage +# from board import * +# import digitalio +# import storage -noStorageStatus = False -noStoragePin = digitalio.DigitalInOut(GP0) -noStoragePin.switch_to_input(pull=digitalio.Pull.UP) -noStorageStatus = not noStoragePin.value +# noStorageStatus = False +# noStoragePin = digitalio.DigitalInOut(GP0) +# noStoragePin.switch_to_input(pull=digitalio.Pull.UP) +# noStorageStatus = not noStoragePin.value -if(noStorageStatus == False): - # don't show USB drive to host PC - storage.disable_usb_drive() - print("Disabling USB drive") -else: - # normal boot - print("USB drive enabled") +# if(noStorageStatus == False): +# # don't show USB drive to host PC +# storage.disable_usb_drive() +# print("Disabling USB drive") +# else: +# # normal boot +# print("USB drive enabled") diff --git a/code.py b/code.py index 46a9d5d..b37dd51 100644 --- a/code.py +++ b/code.py @@ -4,6 +4,7 @@ import time import usb_hid from adafruit_hid.consumer_control_code import ConsumerControlCode from adafruit_hid.consumer_control import ConsumerControl +from adafruit_hid.mouse import Mouse clkPin = digitalio.DigitalInOut(board.GP2) dtPin = digitalio.DigitalInOut(board.GP1) @@ -12,16 +13,48 @@ clkPin.direction = digitalio.Direction.INPUT clkPin.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) +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: - if previousValue != clkPin.value: - if clkPin.value == False: - if dtPin.value == False: - print('left') - consumer_control.send(ConsumerControlCode.VOLUME_DECREMENT) - else: - print('right') - consumer_control.send(ConsumerControlCode.VOLUME_INCREMENT) - previousValue = clkPin.value \ No newline at end of file + 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 + print('Rotary Status: ' + str(clkPin.value))