parent
65fee42217
commit
d36c79ccd9
57
code.py
57
code.py
|
@ -21,11 +21,15 @@ buttonPin.pull = digitalio.Pull.UP
|
||||||
global consumer_control
|
global consumer_control
|
||||||
consumer_control = ConsumerControl(usb_hid.devices)
|
consumer_control = ConsumerControl(usb_hid.devices)
|
||||||
|
|
||||||
|
global mouse
|
||||||
|
mouse = Mouse(usb_hid.devices)
|
||||||
|
|
||||||
global mode
|
global mode
|
||||||
mode = 0
|
mode = 0
|
||||||
global previousValue
|
global previousValue
|
||||||
previousValue = True
|
previousValue = True
|
||||||
|
|
||||||
|
#volume controller
|
||||||
def control_volumen(pinStatus):
|
def control_volumen(pinStatus):
|
||||||
if pinStatus == False:
|
if pinStatus == False:
|
||||||
print('Volumen down')
|
print('Volumen down')
|
||||||
|
@ -39,22 +43,71 @@ def mute_volumen():
|
||||||
print('Mute')
|
print('Mute')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#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')
|
||||||
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
if buttonPin.value == False:
|
if buttonPin.value == False:
|
||||||
if mode == 0:
|
if mode == 0:
|
||||||
mute_volumen()
|
mute_volumen()
|
||||||
|
elif mode == 1:
|
||||||
|
middle_mouse_button()
|
||||||
|
elif mode == 2:
|
||||||
|
play_pause()
|
||||||
else:
|
else:
|
||||||
mode = 0
|
mode = 0
|
||||||
mute_volumen()
|
mute_volumen()
|
||||||
print('Button pressed')
|
print('Button pressed')
|
||||||
time.sleep(0.5)
|
time.sleep(0.3)
|
||||||
|
if buttonPin.value == False:
|
||||||
|
if mode == 0:
|
||||||
|
mute_volumen()
|
||||||
|
mode += 1
|
||||||
|
elif mode == 1:
|
||||||
|
middle_mouse_button()
|
||||||
|
mode += 1
|
||||||
|
elif mode == 2:
|
||||||
|
play_pause()
|
||||||
|
mode += 1
|
||||||
|
else:
|
||||||
|
mode = 0
|
||||||
|
mute_volumen()
|
||||||
|
print("changed mode: " + str(mode))
|
||||||
|
time.sleep(1)
|
||||||
else:
|
else:
|
||||||
if previousValue != clkPin.value:
|
if previousValue != clkPin.value:
|
||||||
if clkPin.value == False:
|
if clkPin.value == False:
|
||||||
if mode == 0:
|
if mode == 0:
|
||||||
control_volumen(dtPin.value)
|
control_volumen(dtPin.value)
|
||||||
|
elif mode == 1:
|
||||||
|
scroll_up_down(dtPin.value)
|
||||||
|
elif mode == 2:
|
||||||
|
previous_next_track(dtPin.value)
|
||||||
else:
|
else:
|
||||||
mode = 0
|
mode = 0
|
||||||
control_volumen(dtPin.value)
|
control_volumen(dtPin.value)
|
||||||
previousValue = clkPin.value
|
previousValue = clkPin.value
|
||||||
print('Rotary Status: ' + str(clkPin.value))
|
|
||||||
|
|
Loading…
Reference in New Issue