Skip to content

Commit 0a1fb9e

Browse files
authored
Merge pull request #2814 from adafruit/dial_update
updating media controller code
2 parents 6c93e10 + ae9efe7 commit 0a1fb9e

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

QT_Py_Media_Controller/code.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,31 @@
1010
from adafruit_seesaw import seesaw, rotaryio, digitalio
1111
from adafruit_hid.consumer_control import ConsumerControl
1212
from adafruit_hid.consumer_control_code import ConsumerControlCode
13+
from adafruit_hid.keyboard import Keyboard
14+
from adafruit_hid.keycode import Keycode
15+
16+
enc_inc = ConsumerControlCode.VOLUME_INCREMENT
17+
enc_dec = ConsumerControlCode.VOLUME_DECREMENT
18+
one_press = ConsumerControlCode.PLAY_PAUSE
19+
two_press = ConsumerControlCode.SCAN_NEXT_TRACK
20+
three_press = [Keycode.LEFT_CONTROL, Keycode.UP_ARROW]
21+
long_press = ConsumerControlCode.MUTE
1322

1423
cc = ConsumerControl(usb_hid.devices)
24+
kbd = Keyboard(usb_hid.devices)
1525

1626
pixel_pin = board.A1
17-
num_pixels = 20
27+
num_pixels = 18
1828
pixels = neopixel.NeoPixel(pixel_pin, num_pixels,
19-
brightness=1, auto_write=True)
29+
brightness=.5, auto_write=True)
2030
hue = 0
2131
pixels.fill(colorwheel(hue))
2232

2333
i2c = board.STEMMA_I2C()
2434
seesaw = seesaw.Seesaw(i2c, 0x36)
2535
seesaw.pin_mode(24, seesaw.INPUT_PULLUP)
2636
ss_pin = digitalio.DigitalIO(seesaw, 24)
27-
button = Button(ss_pin, long_duration_ms=1000)
37+
button = Button(ss_pin, long_duration_ms=600)
2838

2939
encoder = rotaryio.IncrementalEncoder(seesaw)
3040
last_position = 0
@@ -34,17 +44,23 @@
3444
button.update()
3545
if position != last_position:
3646
if position > last_position:
37-
cc.send(ConsumerControlCode.VOLUME_DECREMENT)
47+
cc.send(enc_dec)
3848
hue = hue - 7
3949
if hue <= 0:
4050
hue = hue + 256
4151
else:
42-
cc.send(ConsumerControlCode.VOLUME_INCREMENT)
52+
cc.send(enc_inc)
4353
hue = hue + 7
4454
if hue >= 256:
4555
hue = hue - 256
4656
pixels.fill(colorwheel(hue))
4757
last_position = position
48-
if button.short_count:
49-
# print("Button pressed")
50-
cc.send(ConsumerControlCode.PLAY_PAUSE)
58+
if button.short_count == 1:
59+
cc.send(one_press)
60+
if button.short_count == 2:
61+
cc.send(two_press)
62+
if button.short_count == 3:
63+
kbd.press(*three_press)
64+
kbd.release_all()
65+
if button.long_press:
66+
cc.send(long_press)

0 commit comments

Comments
 (0)