|
10 | 10 | from adafruit_seesaw import seesaw, rotaryio, digitalio |
11 | 11 | from adafruit_hid.consumer_control import ConsumerControl |
12 | 12 | 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 |
13 | 22 |
|
14 | 23 | cc = ConsumerControl(usb_hid.devices) |
| 24 | +kbd = Keyboard(usb_hid.devices) |
15 | 25 |
|
16 | 26 | pixel_pin = board.A1 |
17 | | -num_pixels = 20 |
| 27 | +num_pixels = 18 |
18 | 28 | pixels = neopixel.NeoPixel(pixel_pin, num_pixels, |
19 | | - brightness=1, auto_write=True) |
| 29 | + brightness=.5, auto_write=True) |
20 | 30 | hue = 0 |
21 | 31 | pixels.fill(colorwheel(hue)) |
22 | 32 |
|
23 | 33 | i2c = board.STEMMA_I2C() |
24 | 34 | seesaw = seesaw.Seesaw(i2c, 0x36) |
25 | 35 | seesaw.pin_mode(24, seesaw.INPUT_PULLUP) |
26 | 36 | ss_pin = digitalio.DigitalIO(seesaw, 24) |
27 | | -button = Button(ss_pin, long_duration_ms=1000) |
| 37 | +button = Button(ss_pin, long_duration_ms=600) |
28 | 38 |
|
29 | 39 | encoder = rotaryio.IncrementalEncoder(seesaw) |
30 | 40 | last_position = 0 |
|
34 | 44 | button.update() |
35 | 45 | if position != last_position: |
36 | 46 | if position > last_position: |
37 | | - cc.send(ConsumerControlCode.VOLUME_DECREMENT) |
| 47 | + cc.send(enc_dec) |
38 | 48 | hue = hue - 7 |
39 | 49 | if hue <= 0: |
40 | 50 | hue = hue + 256 |
41 | 51 | else: |
42 | | - cc.send(ConsumerControlCode.VOLUME_INCREMENT) |
| 52 | + cc.send(enc_inc) |
43 | 53 | hue = hue + 7 |
44 | 54 | if hue >= 256: |
45 | 55 | hue = hue - 256 |
46 | 56 | pixels.fill(colorwheel(hue)) |
47 | 57 | 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