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

#include <DebouncedDualButton.h>

Inheritance diagram for DebouncedDualButton:
Inheritance graph

Public Member Functions

 DebouncedDualButton (AbstractButton &button1, AbstractButton &button2)
 
void begin (bool callBeginInChildren=true, 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 ()
 
virtual void begin ()
 
- Public Member Functions inherited from DualInputButton
 DualInputButton (AbstractButton &button1, AbstractButton &button2, const MixMode mix=Or)
 
void begin (bool callBeginInChildren=true)
 
bool on ()
 

Additional Inherited Members

- Public Types inherited from DualInputButton
enum  MixMode { Or, Xor, And }
 
- 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 DualInputButton
AbstractButton_button1
 
AbstractButton_button2
 
const MixMode _mix
 

Detailed Description

Timeslice-based dual input button with debouncing

This class adds debouncing to a DualInputButton.

Definition at line 12 of file DebouncedDualButton.h.

Constructor & Destructor Documentation

◆ DebouncedDualButton()

DebouncedDualButton::DebouncedDualButton ( AbstractButton button1,
AbstractButton button2 
)

Constructor.

Parameters
button1a reference to the first button input.
button2a reference to the second button input.

Definition at line 6 of file DebouncedDualButton.cpp.

Member Function Documentation

◆ begin()

void DebouncedDualButton::begin ( bool  callBeginInChildren = true,
uint8_t  threshold = AbstractDebouncedButton::DefaultThreshold,
uint8_t  delay = AbstractDebouncedButton::DefaultButtonDelay 
)

Initialization.

Parameters
callBeginInChildrenif true, begin() will be called in the two button objects referenced in the constructor. If false, that will be left to the user (in case they want to call begin with non-defalt 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 DebouncedDualButton.cpp.

Here is the call graph for this function:

◆ on()

bool DebouncedDualButton::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 DebouncedDualButton.cpp.

◆ update()

void DebouncedDualButton::update ( )
virtual

Allocate timeslice.

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

Implements AbstractDebouncedButton.

Definition at line 17 of file DebouncedDualButton.cpp.

Here is the call graph for this function:

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