Skip to content

Instantly share code, notes, and snippets.

@wildestpixel
Created May 27, 2021 05:39
Show Gist options
  • Save wildestpixel/6ce7e31fa60b8fd409590ec58f7da647 to your computer and use it in GitHub Desktop.
Save wildestpixel/6ce7e31fa60b8fd409590ec58f7da647 to your computer and use it in GitHub Desktop.
Quick code to create a volume and pause play encoder in CP 6.3
# SPDX-FileCopyrightText: 2021 John Furcean
# SPDX-License-Identifier: MIT
import board
from adafruit_seesaw.seesaw import Seesaw
from adafruit_seesaw.digitalio import DigitalIO
from adafruit_seesaw.rotaryio import IncrementalEncoder
from adafruit_hid.consumer_control import ConsumerControl
from adafruit_hid.consumer_control_code import ConsumerControlCode
import usb_hid
cc = ConsumerControl(usb_hid.devices)
i2c_bus = board.I2C()
seesaw = Seesaw(i2c_bus, addr=0x36)
seesaw_product = (seesaw.get_version() >> 16) & 0xFFFF
print("Found product {}".format(seesaw_product))
if seesaw_product != 4991:
print("Wrong firmware loaded? Expected 4991")
cc = ConsumerControl(usb_hid.devices)
button = DigitalIO(seesaw, 24)
button_held = False
encoder = IncrementalEncoder(seesaw)
button_state = None
last_position = encoder.position
while True:
# read position of the rotary encoder
current_position = encoder.position
position_change = current_position - last_position
if position_change < 0:
for _ in range(-position_change):
cc.send(ConsumerControlCode.VOLUME_INCREMENT)
print(current_position)
elif position_change > 0:
for _ in range(position_change):
cc.send(ConsumerControlCode.VOLUME_DECREMENT)
print(current_position)
last_position = current_position
if not button.value and button_state is None:
button_state = "pressed"
if button.value and button_state == "pressed":
print("Button pressed.")
cc.send(ConsumerControlCode.PLAY_PAUSE)
button_state = None
@wildestpixel
Copy link
Author

Reversed the direction of increment and decrement - testing on RP2040 feather where still seems reversed by default, so manually reverted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment