|
| 1 | +# SPDX-FileCopyrightText: 2024 Liz Clark for Adafruit Industries |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: MIT |
| 4 | + |
| 5 | +import board |
| 6 | +import usb_hid |
| 7 | +import neopixel |
| 8 | +from rainbowio import colorwheel |
| 9 | +from adafruit_debouncer import Button |
| 10 | +from adafruit_seesaw import seesaw, rotaryio, digitalio |
| 11 | +from adafruit_hid.consumer_control import ConsumerControl |
| 12 | +from adafruit_hid.consumer_control_code import ConsumerControlCode |
| 13 | + |
| 14 | +cc = ConsumerControl(usb_hid.devices) |
| 15 | + |
| 16 | +pixel_pin = board.A1 |
| 17 | +num_pixels = 20 |
| 18 | +pixels = neopixel.NeoPixel(pixel_pin, num_pixels, |
| 19 | + brightness=1, auto_write=True) |
| 20 | +hue = 0 |
| 21 | +pixels.fill(colorwheel(hue)) |
| 22 | + |
| 23 | +i2c = board.STEMMA_I2C() |
| 24 | +seesaw = seesaw.Seesaw(i2c, 0x36) |
| 25 | +seesaw.pin_mode(24, seesaw.INPUT_PULLUP) |
| 26 | +ss_pin = digitalio.DigitalIO(seesaw, 24) |
| 27 | +button = Button(ss_pin, long_duration_ms=1000) |
| 28 | + |
| 29 | +encoder = rotaryio.IncrementalEncoder(seesaw) |
| 30 | +last_position = 0 |
| 31 | + |
| 32 | +while True: |
| 33 | + position = -encoder.position |
| 34 | + button.update() |
| 35 | + if position != last_position: |
| 36 | + if position > last_position: |
| 37 | + cc.send(ConsumerControlCode.VOLUME_DECREMENT) |
| 38 | + hue = hue - 7 |
| 39 | + if hue <= 0: |
| 40 | + hue = hue + 256 |
| 41 | + else: |
| 42 | + cc.send(ConsumerControlCode.VOLUME_INCREMENT) |
| 43 | + hue = hue + 7 |
| 44 | + if hue >= 256: |
| 45 | + hue = hue - 256 |
| 46 | + pixels.fill(colorwheel(hue)) |
| 47 | + last_position = position |
| 48 | + if button.short_count: |
| 49 | + # print("Button pressed") |
| 50 | + cc.send(ConsumerControlCode.PLAY_PAUSE) |
0 commit comments