Mutila: Mouse's Utilities for Arduino
Oft-used utilities: debouncing buttons, averaging samples, and so on.
Public Member Functions | List of all members
DebouncedButton Class Reference

#include <DebouncedButton.h>

Inheritance diagram for DebouncedButton:
Inheritance graph

Public Member Functions

 DebouncedButton (uint8_t pin, bool pullup=true)
 
virtual ~DebouncedButton ()
 
void begin (uint8_t threshold=AbstractDebouncedButton::DefaultThreshold, uint8_t delay=AbstractDebouncedButton::DefaultButtonDelay)
 
void update ()
 
bool on ()
 
- Public Member Functions inherited from AbstractDebouncedButton
 AbstractDebouncedButton ()
 
void begin (uint8_t threshold=DefaultThreshold, uint8_t delay=DefaultButtonDelay)
 
bool pushed (bool peek=false)
 
uint32_t tapped (bool peek=false)
 
bool held (uint16_t ms=DefaultHeldMs)
 
bool repeat (uint16_t initialMs=DefaultButtonRepeatInitialMs, uint16_t repeatMs=DefaultButtonRepeatMs)
 
void setState (bool newState)
 
- Public Member Functions inherited from AbstractButton
 AbstractButton ()
 
- Public Member Functions inherited from DigitalInputButton
 DigitalInputButton (const uint8_t pin, const bool pullup=true)
 
void begin ()
 
bool on ()
 

Additional Inherited Members

- Static Public Attributes inherited from AbstractDebouncedButton
static const uint8_t DefaultThreshold = 5
 
static const uint8_t DefaultButtonDelay = 5
 
static const uint16_t DefaultHeldMs = 800
 
static const uint16_t DefaultButtonRepeatInitialMs = 700
 
static const uint16_t DefaultButtonRepeatMs = 350
 
- Protected Attributes inherited from AbstractDebouncedButton
uint8_t _threshold
 
uint8_t _delay
 
uint32_t _lastUpdate
 
uint8_t _counter
 
bool _state
 
uint32_t _lastStateChange
 
bool _pushed
 
uint16_t _repeatCount
 
uint32_t _lastRepeat
 
uint32_t _lastOnDuration
 
- Protected Attributes inherited from DigitalInputButton
const uint8_t _pin
 
const bool _pullup
 

Detailed Description

Timeslice-based button with debouncing

DebouncedButton reduces / eliminates bouncing (multiple press events registing close together with only one physical press).

The update() method must be called frequently (usually from loop()) to work properly.

Definition at line 15 of file DebouncedButton.h.

Constructor & Destructor Documentation

◆ DebouncedButton()

DebouncedButton::DebouncedButton ( uint8_t  pin,
bool  pullup = true 
)

Constructor.

Parameters
pinthe pin used for this button.
pullupif true pin==LOW means on, else pin==HIGH is on.

Definition at line 6 of file DebouncedButton.cpp.

◆ ~DebouncedButton()

virtual DebouncedButton::~DebouncedButton ( )
inlinevirtual

Destructor

Must have this to derive from DebouncedButton without warnings.

Definition at line 28 of file DebouncedButton.h.

Member Function Documentation

◆ begin()

void DebouncedButton::begin ( uint8_t  threshold = AbstractDebouncedButton::DefaultThreshold,
uint8_t  delay = AbstractDebouncedButton::DefaultButtonDelay 
)

Initialization.

Parameters
thresholdhow many tests of the pin must match for a state change.
delaynumber of ms between tests of pin state.

Should be called from setup(), or at any rate, before other members are called. This will set the pinMode. The minimum time it takes for button presses / released to register is threshold * delay.

Definition at line 11 of file DebouncedButton.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ on()

bool DebouncedButton::on ( )
virtual

Test instantaneous input state (with debouncing).

Returns
true if the button is pushed, else false.

Implements AbstractButton.

Definition at line 31 of file DebouncedButton.cpp.

Here is the caller graph for this function:

◆ update()

void DebouncedButton::update ( )
virtual

Allocate timeslice.

This method must be called frequently - usually from loop().

Implements AbstractDebouncedButton.

Definition at line 17 of file DebouncedButton.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

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