Example #1
0
import board
import math
from keybow2040 import Keybow2040, number_to_xy, hsv_to_rgb
import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
from adafruit_hid.keycode import Keycode

i2c = board.I2C()
keybow = Keybow2040(i2c)
keys = keybow.keys
keyboard = Keyboard(usb_hid.devices)
layout = KeyboardLayoutUS(keyboard)

keymap = [
    "rad1", "rad1", "mpc toggle", "toggle_disp1", "rad2", "rad2", "mpc stop",
    "volm", "rad3", "rad3", "mpc prev", "vold", "rad4", "rad4", "mpc next",
    "volu"
]


def rainbow_on():
    global step
    step += 1
    for i in range(16):
        x, y = number_to_xy(i)
        hue = (x + y + (step / 20)) / 8
        hue = hue - int(hue)
        hue = hue - math.floor(hue)
        r, g, b = hsv_to_rgb(hue, 1, 1)
        keys[i].set_led(r, g, b)
Example #2
0
# SPDX-FileCopyrightText: 2021 Sandy Macdonald
#
# SPDX-License-Identifier: MIT

# This example demonstrates attaching functions to keys using decorators, and
# the ability to turn the LEDs off with led_sleep_enabled and led_sleep_time.

# Drop the `keybow2040.py` file and `keybow_hardware` folder
# into your `lib` folder on your `CIRCUITPY` drive.

from keybow2040 import Keybow2040
from keybow_hardware.pim56x import PIM56X as Hardware # for Keybow 2040
#from keybow_hardware.pim551 import PIM551 as Hardware # for Pico RGB Keypad Base

# Set up Keybow
keybow = Keybow2040(Hardware())
keys = keybow.keys

# Enable LED sleep and set a time of 5 seconds before the LEDs turn off.
# They'll turn back on with a tap of any key!
keybow.led_sleep_enabled = True
keybow.led_sleep_time = 5

# Loop through the keys and set the RGB colour for the keys to magenta.
for key in keys:
    key.rgb = (255, 0, 255)

    # Attach a `on_hold` decorator to the key that toggles the key's LED when
    # the key is held (the default hold time is 0.75 seconds).
    @keybow.on_hold(key)
    def hold_handler(key):