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)
# Set up Keybow i2c = board.I2C() keybow = Keybow2040(i2c) 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 # Set up the modifier key. It's 0, or the bottom left key. modifier_key = keys[MODIFIER_KEY] modifier_key.modifier = True # The starting colour (black/off) rgb = (0, 0, 0) while True: # Always remember to call keybow.update()! keybow.update() # If the modifier key and any other key are pressed, then set all the # keys to the selected colour. The second key pressed picks the colour. if modifier_key.held and keybow.any_pressed: if len(keybow.get_pressed()) > 1: hue = max(keybow.get_pressed()) / 15.0 rgb = hsv_to_rgb(hue, 1.0, 1.0) keybow.set_all(*rgb)
keyboard.release(Keycode.LEFT_CONTROL, Keycode.LEFT_SHIFT, binding) @keybow.on_hold(key) def hold_handler(key): pass while True: # Always remember to call keybow.update() on every iteration of your loop! keybow.update() step += 1 for i in range(16): # Convert the key number to an x/y coordinate to calculate the hue # in a matrix style-y. x, y = number_to_xy(i) # Calculate the hue. hue = (x + y + (step / 20)) / 8 hue = hue - int(hue) hue = hue - math.floor(hue) # Convert the hue to RGB values. r, g, b = hsv_to_rgb(hue, 1, 1) # Display it on the key! if i == active or states[i]: keys[i].set_led(r, g, b) else: keys[i].set_led(int(r / 10.0), int(g / 10.0), int(b / 10.0))