Created
May 27, 2021 05:39
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Reversed the direction of increment and decrement - testing on RP2040 feather where still seems reversed by default, so manually reverted