2022-04-26 16:00:29 +00:00
|
|
|
import board
|
|
|
|
import digitalio
|
|
|
|
import time
|
|
|
|
import usb_hid
|
|
|
|
from adafruit_hid.consumer_control_code import ConsumerControlCode
|
|
|
|
from adafruit_hid.consumer_control import ConsumerControl
|
2022-04-26 19:33:41 +00:00
|
|
|
from adafruit_hid.mouse import Mouse
|
2022-04-26 16:00:29 +00:00
|
|
|
|
|
|
|
clkPin = digitalio.DigitalInOut(board.GP2)
|
|
|
|
dtPin = digitalio.DigitalInOut(board.GP1)
|
|
|
|
dtPin.direction= digitalio.Direction.INPUT
|
|
|
|
clkPin.direction = digitalio.Direction.INPUT
|
|
|
|
clkPin.pull = digitalio.Pull.UP
|
|
|
|
dtPin.pull = digitalio.Pull.UP
|
|
|
|
|
2022-04-26 19:33:41 +00:00
|
|
|
global buttonPin
|
|
|
|
buttonPin = digitalio.DigitalInOut(board.GP15)
|
|
|
|
buttonPin.direction = digitalio.Direction.INPUT
|
|
|
|
buttonPin.pull = digitalio.Pull.UP
|
|
|
|
|
|
|
|
global consumer_control
|
2022-04-26 16:00:29 +00:00
|
|
|
consumer_control = ConsumerControl(usb_hid.devices)
|
|
|
|
|
2022-04-26 20:03:45 +00:00
|
|
|
global mouse
|
|
|
|
mouse = Mouse(usb_hid.devices)
|
|
|
|
|
2022-04-26 19:33:41 +00:00
|
|
|
global mode
|
|
|
|
mode = 0
|
|
|
|
global previousValue
|
|
|
|
previousValue = True
|
|
|
|
|
2022-04-26 20:03:45 +00:00
|
|
|
#volume controller
|
2022-04-26 19:33:41 +00:00
|
|
|
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')
|
|
|
|
|
|
|
|
|
2022-04-26 20:03:45 +00:00
|
|
|
|
|
|
|
#quickscroll
|
|
|
|
def scroll_up_down(pinStatus):
|
|
|
|
if pinStatus == False:
|
|
|
|
print('Scroll down')
|
|
|
|
mouse.move(wheel=3)
|
|
|
|
else:
|
|
|
|
print('Scroll up')
|
|
|
|
mouse.move(wheel=-3)
|
|
|
|
|
|
|
|
def middle_mouse_button():
|
|
|
|
mouse.click(Mouse.MIDDLE_BUTTON)
|
|
|
|
|
|
|
|
#media control
|
|
|
|
def previous_next_track(pinStatus):
|
|
|
|
if pinStatus == False:
|
|
|
|
print('Previous track')
|
|
|
|
consumer_control.send(ConsumerControlCode.SCAN_PREVIOUS_TRACK)
|
|
|
|
else:
|
|
|
|
print('Next track')
|
|
|
|
consumer_control.send(ConsumerControlCode.SCAN_NEXT_TRACK)
|
|
|
|
|
|
|
|
def play_pause():
|
|
|
|
consumer_control.send(ConsumerControlCode.PLAY_PAUSE)
|
|
|
|
print('Play/Pause')
|
|
|
|
|
2022-04-26 20:13:20 +00:00
|
|
|
time.sleep(1)
|
2022-04-26 20:03:45 +00:00
|
|
|
|
2022-04-26 16:00:29 +00:00
|
|
|
while True:
|
2022-04-26 19:33:41 +00:00
|
|
|
if buttonPin.value == False:
|
|
|
|
if mode == 0:
|
|
|
|
mute_volumen()
|
2022-04-26 20:03:45 +00:00
|
|
|
elif mode == 1:
|
2022-05-03 17:24:20 +00:00
|
|
|
play_pause()
|
2022-04-26 20:03:45 +00:00
|
|
|
middle_mouse_button()
|
|
|
|
elif mode == 2:
|
2022-05-03 17:24:20 +00:00
|
|
|
middle_mouse_button()
|
2022-04-26 19:33:41 +00:00
|
|
|
else:
|
|
|
|
mode = 0
|
|
|
|
mute_volumen()
|
|
|
|
print('Button pressed')
|
2022-04-26 20:03:45 +00:00
|
|
|
time.sleep(0.3)
|
|
|
|
if buttonPin.value == False:
|
|
|
|
if mode == 0:
|
|
|
|
mute_volumen()
|
|
|
|
mode += 1
|
|
|
|
elif mode == 1:
|
2022-05-03 17:24:20 +00:00
|
|
|
play_pause()
|
2022-04-26 20:03:45 +00:00
|
|
|
middle_mouse_button()
|
|
|
|
mode += 1
|
|
|
|
elif mode == 2:
|
2022-05-03 17:24:20 +00:00
|
|
|
middle_mouse_button()
|
2022-04-26 20:03:45 +00:00
|
|
|
mode += 1
|
|
|
|
else:
|
|
|
|
mode = 0
|
|
|
|
mute_volumen()
|
|
|
|
print("changed mode: " + str(mode))
|
|
|
|
time.sleep(1)
|
2022-04-26 19:33:41 +00:00
|
|
|
else:
|
|
|
|
if previousValue != clkPin.value:
|
|
|
|
if clkPin.value == False:
|
|
|
|
if mode == 0:
|
|
|
|
control_volumen(dtPin.value)
|
2022-04-26 20:03:45 +00:00
|
|
|
elif mode == 1:
|
|
|
|
scroll_up_down(dtPin.value)
|
|
|
|
elif mode == 2:
|
|
|
|
previous_next_track(dtPin.value)
|
2022-04-26 19:33:41 +00:00
|
|
|
else:
|
|
|
|
mode = 0
|
|
|
|
control_volumen(dtPin.value)
|
2022-04-26 20:03:45 +00:00
|
|
|
previousValue = clkPin.value
|