wpi-32u4-library
|
Main class for interfacing with pushbuttons. More...
#include <Pushbutton.h>
Inherits PushbuttonBase.
Inherited by Romi32U4ButtonA.
Public Member Functions | |
Pushbutton (uint8_t pin, uint8_t pullUp=PULL_UP_ENABLED, uint8_t defaultState=DEFAULT_STATE_HIGH) | |
virtual bool | isPressed () |
indicates whether button is currently pressed without any debouncing. More... | |
![]() | |
void | waitForPress () |
Waits until the button is pressed and takes care of debouncing. More... | |
void | waitForRelease () |
Waits until the button is released and takes care of debouncing. More... | |
void | waitForButton () |
Waits until the button is pressed and then waits until the button is released, taking care of debouncing. More... | |
bool | getSingleDebouncedPress () |
Uses a state machine to return true once after each time it detects the button moving from the released state to the pressed state. More... | |
bool | getSingleDebouncedRelease () |
Uses a state machine to return true once after each time it detects the button moving from the pressed state to the released state. More... | |
virtual bool | isPressed ()=0 |
indicates whether button is currently pressed without any debouncing. More... | |
Private Member Functions | |
void | init () |
void | init2 () |
Private Attributes | |
bool | initialized |
uint8_t | _pin |
bool | _pullUp |
bool | _defaultState |
Main class for interfacing with pushbuttons.
This class can interface with any pushbutton whose state can be read with the digitalRead
function, which is part of the Arduino core.
See https://github.com/pololu/pushbutton-arduino for an overview of the different ways to use this class.
Definition at line 137 of file Pushbutton.h.
Pushbutton::Pushbutton | ( | uint8_t | pin, |
uint8_t | pullUp = PULL_UP_ENABLED , |
||
uint8_t | defaultState = DEFAULT_STATE_HIGH |
||
) |
Constructs a new instance of Pushbutton.
pin | The pin number of the pin. This is used as an argument to pinMode and digitalRead . |
pullUp | Specifies whether the pin's internal pull-up resistor should be enabled. This should be either PULL_UP_ENABLED (which is the default if the argument is omitted) or PULL_UP_DISABLED. |
defaultState | Specifies the voltage level that corresponds to the button's default (released) state. This should be either DEFAULT_STATE_HIGH (which is the default if this argument is omitted) or DEFAULT_STATE_LOW. |
Definition at line 120 of file Pushbutton.cpp.
References _defaultState, _pin, _pullUp, and initialized.
|
inlineprivate |
Definition at line 161 of file Pushbutton.h.
References init2(), and initialized.
Referenced by isPressed().
|
private |
Definition at line 128 of file Pushbutton.cpp.
References _pin, _pullUp, and PULL_UP_ENABLED.
Referenced by init().
|
virtual |
indicates whether button is currently pressed without any debouncing.
This function must be implemented in a subclass of PushbuttonBase, such as Pushbutton.
Implements PushbuttonBase.
Definition at line 142 of file Pushbutton.cpp.
References _defaultState, _pin, and init().
|
private |
Definition at line 175 of file Pushbutton.h.
Referenced by isPressed(), and Pushbutton().
|
private |
Definition at line 173 of file Pushbutton.h.
Referenced by init2(), isPressed(), and Pushbutton().
|
private |
Definition at line 174 of file Pushbutton.h.
Referenced by init2(), and Pushbutton().
|
private |
Definition at line 172 of file Pushbutton.h.
Referenced by init(), and Pushbutton().