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

Timeslice-based button with debouncing using analogRead. More...

#include <DebouncedAnalogButton.h>

Inheritance diagram for DebouncedAnalogButton:
Inheritance graph

Public Member Functions

 DebouncedAnalogButton (const uint8_t pin, const bool pullup=true, const uint16_t analogThreshold=512)
 
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 AnalogInputButton
 AnalogInputButton (const uint8_t pin, const bool pullup=true, const uint16_t analogThreshold=512)
 
void begin ()
 

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 AnalogInputButton
const uint8_t _pin
 
const bool _pullup
 
const uint16_t _analogThreshold
 

Detailed Description

Timeslice-based button with debouncing using analogRead.

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

This class reads from the pin using analogRead. This is occasionally useful when special analog-only pins need to be used for button inputs (e.g. pins A6 and A7 on the nano).

Definition at line 16 of file DebouncedAnalogButton.h.

Constructor & Destructor Documentation

◆ DebouncedAnalogButton()

DebouncedAnalogButton::DebouncedAnalogButton ( const uint8_t  pin,
const bool  pullup = true,
const uint16_t  analogThreshold = 512 
)

Constructor.

Parameters
pinthe pin used for this button.
pullupif true pin==LOW means on, else pin==HIGH is on.
analogThresholdthe value mid way between the on and off states as reported by analogRead.

Definition at line 5 of file DebouncedAnalogButton.cpp.

Member Function Documentation

◆ begin()

void DebouncedAnalogButton::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 10 of file DebouncedAnalogButton.cpp.

Here is the call graph for this function:

◆ on()

bool DebouncedAnalogButton::on ( )
virtual

Test instantaneous input state (with debouncing)

Returns
true if the button is pushed, else false.

Reimplemented from AnalogInputButton.

Definition at line 31 of file DebouncedAnalogButton.cpp.

◆ update()

void DebouncedAnalogButton::update ( )
virtual

Allocate Timeslice

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

Implements AbstractDebouncedButton.

Definition at line 16 of file DebouncedAnalogButton.cpp.

Here is the call graph for this function:

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