Library that eases interacting with physical buttons through the Raspberry Pi GPIO
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
rpi-controls-1.0.0a1.tar.gz
(22.7 kB
view hashes)
Built Distribution
Close
Hashes for rpi_controls-1.0.0a1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c7e0b63fe781f6190b12ceaf9904c820f0d26090f7bd9d637f661fa1673b690 |
|
MD5 | 5d32305151a307f9af4e32bcb2161bbb |
|
BLAKE2b-256 | b214e0e3105cb5585d3e9df138b213b1f87ddcad58889750f6bf52add8cc4416 |