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)
Beta - version 0.1.1
Copy the rbgkeypad code into your program.
Below is some typical use cases and examples for using the
RGBKeypadclass. See the API documentation for more information.
Create a keypad object.
keypad = RGBKeypad()
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
# 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
1 is full brightness and
0 is off. By default the brightness is set to
keypad.brightness = 1
The keypad can be cleared (turned off) using the
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
# red key1.color = (255, 0, 0) # full brightness key1.brightness = 1
An individual key can also be cleared using the
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
keys_pressed = keypad.get_keys_pressed() print(keys_pressed)