rgbkeypad

A Python class for controlling the Pimoroni RGB Keypad for the Raspberry Pi Pico.

Compatible with MicroPython and CircuitPython.

keypad = RGBKeypad()

# make all the keys red
keypad.color = (255, 0, 0)

# turn a key blue when pressed
while True:
    for key in keypad.keys:
        if key.is_pressed():
            key.color = (0, 0, 255)

pimoroni rgb keypad

Status

Beta - version 0.1.1

Install

Copy the rbgkeypad code into your program.

Usage

Below is some typical use cases and examples for using the RGBKeypad class. See the API documentation for more information.

Create a keypad object.

keypad = RGBKeypad()

Display

The color of all the keys can be changed by setting the key pad's color property to a tuple of (red, green, blue) values between 0 and 255.

# red
keypad.color = (255, 0, 0)

# green
keypad.color = (0, 255, 0)

# blue
keypad.color = (0, 0, 255)

# white
keypad.color = (255, 255, 255)

# yellow
keypad.color = (255, 255, 0)

# purple
keypad.color = (128, 0, 128)

The brightness can be changed by setting the brightness property to a value between 0 and 1. Where 1 is full brightness and 0 is off. By default the brightness is set to 0.5.

keypad.brightness = 1

The keypad can be cleared (turned off) using the clear() method.

keypad.clear()

Individual keys can be referenced using their x,y position e.g. [0,0]

key1 = keypad[0, 0]

Individual key's color and brightness can be set using the color and brightness properties.

# red
key1.color = (255, 0, 0)

# full brightness
key1.brightness = 1

An individual key can also be cleared using the clear() method.

key1.clear()

Press

The status of the key can be retrieved using the is_pressed() method of an individual key.

key1 = keypad[0, 0]
pressed = key1.is_pressed()

Use a loop to continuously check the status of a key.

while True:
    if key1.is_pressed():
        print("key 1 pressed")

To check the status of all the keys, loop through the keypad's keys property, check each individually.

while True:
    for key in keypad.keys:
        if key.is_pressed():
            print("key", key.x, key.y, "pressed)

Alternatively a list of all the keys pressed status can be obtained using the key pad's get_keys_pressed() method.

keys_pressed = keypad.get_keys_pressed()
print(keys_pressed)

GitHub

https://github.com/martinohanlon/pico-rgbkeypad