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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
previousValue = True
|
|
|
|
consumer_control = ConsumerControl(usb_hid.devices)
|
|
|
|
|
|
|
|
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
|