GPIO controller for Raspberry Pi
This package provides classes to interact with physical buttons connected to a Raspberry Pi's GPIO. Those classes make it easy to run event-driven callbacks.
Brief example
The example below illustrates the implementation of a callback to execute asynchronously when clicking a button:
from rpicontrols import Controller, Button, PullType, make_controller
# Initialize the button controller. A single instance can handle as many buttons as needed.
controller: Controller = make_controller()
# Create the button, connected to pin 22.
button: Button = controller.make_button(
input_pin_id=22, # Id of the GPIO pin the button switch is connected to.
input=Button.InputType.PRESSED_WHEN_OFF, # Depends on the physical wiring of the button.
pull=PullType.UP # Whether to enable pull-up or pull-down resistor. Use PullType.NONE to disable.
)
# Define a callback to run when button is clicked.
async def on_click_callback(button: Button) -> None:
print(f'Button {button.name} clicked!')
# Run some IO-bound task without blocking.
# Other event handlers may run while waiting.
await asyncio.sleep(2)
# Subscribe to the click event.
button.add_on_click(on_click_callback)
# Start controller main loop. Use controller.start_in_thread() for the non-blocking version.
controller.run()
Asynchronous callbacks are optional and synchronous ones work just fine. Check out the full documentation here for all the details.
Release files for rpi-controls 1.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| rpi-controls-1.0.3.tar.gz | 22.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| rpi_controls-1.0.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 46.4 kB
Release files / rpi-controls-1.0.3.tar.gz
| Download URL | rpi-controls-1.0.3.tar.gz |
|---|---|
| Size | 22.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2dfba423d3e077ece9b3b5981a5be797fc717deb5050e15a273a159367335366
|
|
BLAKE2b-256 checksum How to use checksums |
cce64b8c0298ee059f5ff3b2cb052a647cd07e733c026ba9af7e94498b5cc07a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.8.10
|
Release files / rpi_controls-1.0.3-py3-none-any.whl
| Download URL | rpi_controls-1.0.3-py3-none-any.whl |
|---|---|
| Size | 23.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
df6c8348a4fe6a46f1a34526e7e94810270629f2afc9beaa3a45e448ba7aa9a4
|
|
BLAKE2b-256 checksum How to use checksums |
96424466db0bcebe367a2347bd4fb6a4e8ed0e17768c0d82876454e5ed43d03a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.8.10
|