rstem.button module
This module provides interfaces to the buttons in the I/O Ready Set STEM Cell.
Classes
A button from a GPIO port.
A Button configures a physical button hooked up to a GPIO
pin. The physical button, when pressed, should connect the GPIO pin to
ground.
Button provides a set of functions that make it easy to
check if and when a button is pressed. The Button object
reads button presses in the background so that the calling program won't
lose presses. Presses and releases are kept in a queue that the caller can
read at any time.
More details: The GPIO is configured with an internal pullup so that when
the button is NOT pressed, the GPIO input is high, and when the button is
pressed, the input is low (shorted to ground). Additionaly, The
Button object handles button debouncing.
Ancestors (in MRO)
- Button
- rstem.gpio.Input
- rstem.gpio.Pin
- builtins.object
Class variables
GPIO number of the 'A' button on the GAMER keypad.
GPIO number of the 'B' button on the GAMER keypad.
GPIO number of the 'DOWN' button on the GAMER keypad.
GPIO number of the 'LEFT' button on the GAMER keypad.
GPIO number of the 'RIGHT' button on the GAMER keypad.
GPIO number of the 'SELECT' button on the GAMER keypad.
GPIO number of the 'START' button on the GAMER keypad.
GPIO number of the 'UP' button on the GAMER keypad.
Static methods
def __init__(
self, pin)
Create a new Button.
pin is the number of the GPIO as labeled on the Ready Set STEM Lid
Connector Board. It is the same as the GPIO number used by the
Broadcom processor on the Raspberry Pi.
def board_rev(
)
def is_pressed(
self, press=True)
Reports if the button is pressed.
Returns True if the button is pressed, otherwise False.
def is_released(
self)
Reports if the button is released.
Equivalent to not is_pressed().
def presses(
self, press=True)
Returns the number of presses since presses/releases were last queried.
Button presses and releases are queued up - this function reads all the presses/releases from the queue and returns the total number of presses. Reading the full queue effectively resets the number of presses and releases to zero.
Alternatively, if press is False, this function returns the number
of releases since presses/releases were last queried.
def releases(
self)
Returns the number of releases since presses/releases were last queried.
Equivalent to presses(press=False).
def staticmethod_wait_many(
buttons, press=True, timeout=None)
Calls wait on a list of buttons.
Given a list of buttons this function will wait for any of them to be
pressed, and return the index into the buttons list of the button
that was pressed. The press and timeout arguments are the same as
for the wait function.
NOTE: This is a staticmethod not an instancemethod, and the
actual name does not include the prefix staticmethod_. It is only
shown with that prefix to allow it to be documented here.
def wait(
self, press=True, timeout=None)
Wait until a press occurs.
This function blocks until a press occurs and (by default) returns
True. Because button presses and releases are queued up, it will
return immediately if a press is already available before the function
was called.
If timeout=None (the default), the function will block forever until
a press occurs. If the timeout is a number 0 or greater, the
function will block for up to timeout time in seconds (floats
allowed). If the timeout time expires before the button is pressed,
the function returns False.
Alternatively, if press is False, this function waits for releases
instead of presses.
def wait_many(
*args, **kwargs)