Reputation: 155
I took an Adafruit code example ([Rotary encoder][1]) for a rotary encoder and changed it in a way that I can control the volume of my PC with a Raspberry Pi Pico as HID.
#
# SPDX-License-Identifier: MIT
import rotaryio
import board
from adafruit_hid.keycode import Keycode
from adafruit_hid.consumer_control_code import ConsumerControlCode
encoder = rotaryio.IncrementalEncoder(board.GP12, board.GP13)
last_position = None
while True:
position = encoder.position
if last_position is None or position != last_position:
if position > last_position:
cc.send(ConsumerControlCode.VOLUME_INCREMENT)
time.sleep(0.01)
print("Volume up")
elif position < last_position:
cc.send(ConsumerControlCode.VOLUME_DECREMENT)
time.sleep(0.01)
print("Volume down")
else:
print("No change")
last_position = position
Unfortunately I get the above mentioned error. I found a similar error here on stackoverflow but it couldn't solve the problem for me.
[1]: https://docs.circuitpython.org/en/latest/shared-bindings/rotaryio/index.html
Upvotes: -1
Views: 24