4.3. button Module¶
4.3.1. Button class¶
Button debounce class, handles button release and long presses.
- Parameters
pin (int) – the pin number the button is connected to.
debounce (int optional) – the debounce time in ms, defaults to 50ms
long – (int optional): the long press interval, defaults to 600ms, a
of 0 will disable reporting of long presses. (value) –
active_high (bool optional) – if True pin reads 1 when pressed. If False
reads 0 when pressed. Defaults the True. (pin) –
Modify button debounce or long press timing
- Parameters
debounce (int) – debounce time in ms
long (int) – long press time in ms
Read button with debounce and long press detection
- Returns
0 if not pressed. 1 if pressed, -1 if long pressed
- Return type
int
4.3.2. JoyStick class¶
JoyStick class, handles reading a five way switch style joystick. Uses the Button class and supports long press notification.
Read JoyStick
- Args: max_wait (optional int): maximum time to wait for button press
in ms.
- Returns: int: the value of the button that was pressed and released.
if the button definition did not set the parameter long to 0, and the button was pressed and held longer then the parameter long in ms the value returned will be negative. If max_wait was specified and max_wait ms pass without a button being pressed amd release a 0 will be returned.