wpi-32u4-library
Public Member Functions | Private Member Functions | Private Attributes
Pushbutton Class Reference

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...
 
- Public Member Functions inherited from PushbuttonBase
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
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ Pushbutton()

Pushbutton::Pushbutton ( uint8_t  pin,
uint8_t  pullUp = PULL_UP_ENABLED,
uint8_t  defaultState = DEFAULT_STATE_HIGH 
)

Constructs a new instance of Pushbutton.

Parameters
pinThe pin number of the pin. This is used as an argument to pinMode and digitalRead.
pullUpSpecifies 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.
defaultStateSpecifies 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.

Member Function Documentation

◆ init()

void Pushbutton::init ( void  )
inlineprivate

Definition at line 161 of file Pushbutton.h.

References init2(), and initialized.

Referenced by isPressed().

◆ init2()

void Pushbutton::init2 ( )
private

Definition at line 128 of file Pushbutton.cpp.

References _pin, _pullUp, and PULL_UP_ENABLED.

Referenced by init().

◆ isPressed()

bool Pushbutton::isPressed ( )
virtual

indicates whether button is currently pressed without any debouncing.

Returns
1 if the button is pressed right now, 0 if it is not.

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().

Field Documentation

◆ _defaultState

bool Pushbutton::_defaultState
private

Definition at line 175 of file Pushbutton.h.

Referenced by isPressed(), and Pushbutton().

◆ _pin

uint8_t Pushbutton::_pin
private

Definition at line 173 of file Pushbutton.h.

Referenced by init2(), isPressed(), and Pushbutton().

◆ _pullUp

bool Pushbutton::_pullUp
private

Definition at line 174 of file Pushbutton.h.

Referenced by init2(), and Pushbutton().

◆ initialized

bool Pushbutton::initialized
private

Definition at line 172 of file Pushbutton.h.

Referenced by init(), and Pushbutton().


The documentation for this class was generated from the following files: