Skip to content

martinohanlon/pico-rgbkeypad

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.2

Install

There are a few options for installing pico rgbkeypad:

  1. Copy the rbgkeypad.py code into the top of your program.

  2. Copy the rgbkeypad folder to the lib folder on your pico (useful if you are using CircuitPython).

  3. Install the pico-rgbkeypad package from PyPi using upip or the Manage Packages tool in Thonny.

Usage

Here you will find some typical use cases and examples for using rgbkeypad. See the API documentation for more information.

Import the RGBKeypad class from the rgbkeypad module.

Note - you do not need to import the module if you copied the rgbkeypad.py code directly into your program.

from rgbkeypad import RGBKeypad

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)

Deploy

These are instructions for how to deploy the pico-rgbkeypad to PyPI

  1. Install pre-requisites
pip3 install setuptools twine
  1. Increment version number in setup.py, README.md and CHANGELOG.MD

  2. Build for deployment

python setup.py sdist
  1. Deploy to PyPI
twine upload dist/* --skip-existing

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages