AStar32U4 library
Public Member Functions | List of all members
Pushbutton Class Reference

Main class for interfacing with pushbuttons. More...

#include <Pushbutton.h>

Inheritance diagram for Pushbutton:
PushbuttonBase AStar32U4ButtonA

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

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

Member Function Documentation

bool PushbuttonBase::getSingleDebouncedPress ( )
inherited

Uses a state machine to return true once after each time it detects the button moving from the released state to the pressed state.

This is a non-blocking function that is meant to be called repeatedly in a loop. Each time it is called, it updates a state machine that monitors the state of the button. When it detects the button changing from the released state to the pressed state, with debouncing, it returns true.

Definition at line 110 of file Pushbutton.cpp.

bool PushbuttonBase::getSingleDebouncedRelease ( )
inherited

Uses a state machine to return true once after each time it detects the button moving from the pressed state to the released state.

This is just like getSingleDebouncedPress() except it has a separate state machine and it watches for when the button goes from the pressed state to the released state.

There is no strict guarantee that every debounced button press event returned by getSingleDebouncedPress() will have a corresponding button release event returned by getSingleDebouncedRelease(); the two functions use independent state machines and sample the button at different times.

Definition at line 115 of file Pushbutton.cpp.

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.

void PushbuttonBase::waitForButton ( )
inherited

Waits until the button is pressed and then waits until the button is released, taking care of debouncing.

This is equivalent to calling waitForPress() and then waitForRelease().

Definition at line 104 of file Pushbutton.cpp.

void PushbuttonBase::waitForPress ( )
inherited

Waits until the button is pressed and takes care of debouncing.

This function waits until the button is in the pressed state and then returns. Note that if the button is already pressed when you call this function, it will return quickly (in 10 ms).

Definition at line 84 of file Pushbutton.cpp.

void PushbuttonBase::waitForRelease ( )
inherited

Waits until the button is released and takes care of debouncing.

This function waits until the button is in the released state and then returns. Note that if the button is already released when you call this function, it will return quickly (in 10 ms).

Definition at line 94 of file Pushbutton.cpp.


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