A class for reading and debouncing buttons and switches. More...
#include <AH/Hardware/Button.hpp>
 Collaboration diagram for Button:Public Types | |
| enum | State { Pressed = 0b00, Released = 0b11, Falling = 0b10, Rising = 0b01 } | 
| An enumeration of the different states a button can be in.  More... | |
Public Member Functions | |
| Button () | |
| Construct a new Button object.  More... | |
| Button (pin_t pin) | |
| Construct a new Button object.  More... | |
| void | begin () | 
| Initialize (enable the internal pull-up resistor).  More... | |
| AH_INDIVIDUAL_BUTTON_INVERT_STATIC void | invert () | 
Invert the state of all buttons, or of this specific button (button pressed is HIGH instead of LOW).  More... | |
| State | update () | 
| Read the button and return its new state.  More... | |
| State | getState () const | 
| Get the state of the button, without updating it.  More... | |
| unsigned long | previousBounceTime () const | 
| Return the time point (in milliseconds) when the button last bounced.  More... | |
| unsigned long | stableTime (unsigned long now) const | 
| Return the time (in milliseconds) that the button has been stable for, compared to the given time point.  More... | |
| unsigned long | stableTime () const | 
| Return the time (in milliseconds) that the button has been stable for.  More... | |
Static Public Member Functions | |
| static FlashString_t | getName (State state) | 
| Return the name of the state as a string.  More... | |
| static void | setDebounceTime (unsigned long debounceTime=BUTTON_DEBOUNCE_TIME) | 
| Set the debounce time for all Buttons.  More... | |
| static unsigned long | getDebounceTime () | 
| Get the debounce time.  More... | |
Private Attributes | |
| pin_t | pin | 
| bool | prevInput = HIGH | 
| State | debouncedState = Released | 
| unsigned long | prevBounceTime = 0 | 
| bool | invertState = false | 
Static Private Attributes | |
| static unsigned long | debounceTime = BUTTON_DEBOUNCE_TIME | 
| Edit this in Settings.hpp.  More... | |
A class for reading and debouncing buttons and switches.
Definition at line 18 of file Button.hpp.
| enum State | 
An enumeration of the different states a button can be in.
| Enumerator | |
|---|---|
| Pressed | Input went from low to low (0,0)  | 
| Released | Input went from high to high (1,1)  | 
| Falling | Input went from high to low (1,0)  | 
| Rising | Input went from low to high (0,1)  | 
Definition at line 53 of file Button.hpp.
      
  | 
  inline | 
Construct a new Button object.
This constructor should not be used. 
 It is just a way to easily create arrays of buttons, and initializing them later. 
Definition at line 27 of file Button.hpp.
Construct a new Button object.
| pin | The digital pin to read from. The internal pull-up resistor will be enabled when begin is called.  | 
Definition at line 9 of file Button.cpp.
| void begin | ( | ) | 
Initialize (enable the internal pull-up resistor).
Definition at line 11 of file Button.cpp.
| void invert | ( | ) | 
Invert the state of all buttons, or of this specific button (button pressed is HIGH instead of LOW). 
AH_INDIVIDUAL_BUTTON_INVERT is not defined.Definition at line 13 of file Button.cpp.
| Button::State update | ( | ) | 
Read the button and return its new state.
The button is debounced, the debounce time can be set in Settings.hpp: BUTTON_DEBOUNCE_TIME.
Definition at line 19 of file Button.cpp.
| Button::State getState | ( | ) | const | 
Get the state of the button, without updating it.
Returns the same value as the last call to update.
Definition at line 36 of file Button.cpp.
      
  | 
  static | 
Return the name of the state as a string.
Definition at line 38 of file Button.cpp.
| unsigned long previousBounceTime | ( | ) | const | 
Return the time point (in milliseconds) when the button last bounced.
Definition at line 48 of file Button.cpp.
| unsigned long stableTime | ( | unsigned long | now | ) | const | 
Return the time (in milliseconds) that the button has been stable for, compared to the given time point.
Definition at line 50 of file Button.cpp.
| unsigned long stableTime | ( | ) | const | 
Return the time (in milliseconds) that the button has been stable for.
Definition at line 54 of file Button.cpp.
      
  | 
  static | 
Set the debounce time for all Buttons.
| debounceTime | The new debounce time in milliseconds. | 
Definition at line 56 of file Button.cpp.
      
  | 
  static | 
Get the debounce time.
Definition at line 60 of file Button.cpp.
      
  | 
  private | 
Definition at line 130 of file Button.hpp.
      
  | 
  private | 
Definition at line 132 of file Button.hpp.
Definition at line 133 of file Button.hpp.
      
  | 
  private | 
Definition at line 134 of file Button.hpp.
      
  | 
  private | 
Definition at line 137 of file Button.hpp.
      
  | 
  staticprivate |