AbleButtons V0.2.0
Lightweight button library for Arduino.
 
Loading...
Searching...
No Matches
able::DoubleClickerPin Class Reference

Pin class that counts state changes within a time-period. More...

#include <Pins.h>

+ Inheritance diagram for able::DoubleClickerPin:

Static Public Member Functions

static void setClickTime (uint16_t clickTime)
 Set the click time for input pins. More...
 
static uint16_t clickTime ()
 Return the double-click time. More...
 
static void setDebounceTime (uint8_t debounceTime)
 Set the debounce time for input pins. More...
 
static void setHeldTime (uint16_t heldTime)
 Set the held time for input pins. More...
 
static void setIdleTime (uint32_t idleTime)
 Set the idle time for input pins. More...
 
static uint8_t debounceTime ()
 Return the pin debounce time. More...
 
static uint16_t heldTime ()
 Return the pin held time. More...
 
static uint32_t idleTime ()
 Return the pin idle time. More...
 

Protected Member Functions

 DoubleClickerPin (uint8_t pin, uint8_t initState)
 Protected constructor used by sub-classes. More...
 
void readPin ()
 Debounce the pin readings to get a stable state of the pin. More...
 

Static Protected Member Functions

static uint8_t nextId ()
 Return the next auto-assigned button identifier. More...
 

Protected Attributes

uint8_t stateCount_
 Count changes in state within double-click time. More...
 
unsigned long prevMillis_
 Previous millisecond count from last state change. More...
 
uint8_t prevState_
 Previous debounced reading of the pin. More...
 
uint8_t prevReading_
 The previous pin reading, to monitor state transitions. More...
 
unsigned long millisStart_
 Debounce start timer to handle button transition. More...
 
uint8_t pin_
 The Arduino pin connected to the button. More...
 
uint8_t currState_
 The reading of the pin. More...
 

Static Protected Attributes

static uint16_t clickTime_ = 250
 Time required for button to be double-clicked. More...
 
static uint8_t debounceTime_ = 50
 Time required to debounce all input pins. More...
 
static uint16_t heldTime_ = 1000
 Time required for button to be held. More...
 
static uint32_t idleTime_ = 60000
 Time required for button to be idle. More...
 
static uint8_t autoId_ = 0
 Auto-assigned button identifier. More...
 

Detailed Description

Pin class that counts state changes within a time-period.

This enables it to identify double-clicks.

Definition at line 274 of file Pins.h.

Constructor & Destructor Documentation

◆ DoubleClickerPin()

able::DoubleClickerPin::DoubleClickerPin ( uint8_t  pin,
uint8_t  initState 
)
inlineprotected

Protected constructor used by sub-classes.

Use a Button sub-class of this class instead of this class directly.

Parameters
pinThe pin to read from.
initStateThe initial (un-pushed) state of the button.

Definition at line 303 of file Pins.h.

Member Function Documentation

◆ clickTime()

static uint16_t able::DoubleClickerPin::clickTime ( )
inlinestatic

Return the double-click time.

Returns
The number of milliseconds of debounce time.

Definition at line 323 of file Pins.h.

◆ debounceTime()

static uint8_t able::DebouncedPin::debounceTime ( )
inlinestaticinherited

Return the pin debounce time.

Returns
The number of milliseconds of debounce time.

Definition at line 179 of file Pins.h.

◆ heldTime()

static uint16_t able::DebouncedPin::heldTime ( )
inlinestaticinherited

Return the pin held time.

Returns
The number of milliseconds after which a pin is held.

Definition at line 188 of file Pins.h.

◆ idleTime()

static uint32_t able::DebouncedPin::idleTime ( )
inlinestaticinherited

Return the pin idle time.

Returns
The number of milliseconds after which a pin is idle.

Definition at line 197 of file Pins.h.

◆ nextId()

static uint8_t able::Pin::nextId ( )
inlinestaticprotectedinherited

Return the next auto-assigned button identifier.

Returns
The next auto-assigned button identifier. Each call increases the auto-assigned identifier.

Definition at line 29 of file Pins.h.

◆ readPin()

void able::DoubleClickerPin::readPin ( )
inlineprotected

Debounce the pin readings to get a stable state of the pin.

When the state changes, remember the previous state so clicks (press then release can be identified). Calls DebouncedPin::readPin() and monitors for a change in debounced state, remembering the previous state.

Definition at line 338 of file Pins.h.

◆ setClickTime()

static void able::DoubleClickerPin::setClickTime ( uint16_t  clickTime)
inlinestatic

Set the click time for input pins.

If a button is clicked again within this millisecond value, it will be counted, else the count resets. Allows tracking of double-clicks within the specified time.

Parameters
clickTimeThe number of milliseconds between clicks.

Definition at line 287 of file Pins.h.

◆ setDebounceTime()

static void able::DebouncedPin::setDebounceTime ( uint8_t  debounceTime)
inlinestaticinherited

Set the debounce time for input pins.

Pins may read noise as buttons are pressed and released. This noise can be registered as multiple button presses in a short time period, confusing your program. The debounce time is the number of milliseconds to wait when a reading changes before using that reading. See https://docs.arduino.cc/built-in-examples/digital/Debounce for details on debounce.

Parameters
debounceTimeThe number of milliseconds before a button state change is returned (default 50ms, max 255ms).

Definition at line 98 of file Pins.h.

◆ setHeldTime()

static void able::DebouncedPin::setHeldTime ( uint16_t  heldTime)
inlinestaticinherited

Set the held time for input pins.

If a button is pressed for longer than this time, it will be held.

Parameters
heldTimeThe number of milliseconds for a held state (default 1s).

Definition at line 108 of file Pins.h.

◆ setIdleTime()

static void able::DebouncedPin::setIdleTime ( uint32_t  idleTime)
inlinestaticinherited

Set the idle time for input pins.

If a button is unpressed for longer than this time, it will be idle.

Parameters
idleTimeThe number of milliseconds for an idle state (default 60s).

Definition at line 118 of file Pins.h.

Member Data Documentation

◆ autoId_

uint8_t able::Pin::autoId_ = 0
staticprotectedinherited

Auto-assigned button identifier.

Definition at line 70 of file Pins.h.

◆ clickTime_

uint16_t able::DoubleClickerPin::clickTime_ = 250
staticprotected

Time required for button to be double-clicked.

Definition at line 361 of file Pins.h.

◆ currState_

uint8_t able::Pin::currState_
protectedinherited

The reading of the pin.

Definition at line 73 of file Pins.h.

◆ debounceTime_

uint8_t able::DebouncedPin::debounceTime_ = 50
staticprotectedinherited

Time required to debounce all input pins.

Definition at line 205 of file Pins.h.

◆ heldTime_

uint16_t able::DebouncedPin::heldTime_ = 1000
staticprotectedinherited

Time required for button to be held.

Definition at line 206 of file Pins.h.

◆ idleTime_

uint32_t able::DebouncedPin::idleTime_ = 60000
staticprotectedinherited

Time required for button to be idle.

Definition at line 207 of file Pins.h.

◆ millisStart_

unsigned long able::DebouncedPin::millisStart_
protectedinherited

Debounce start timer to handle button transition.

Definition at line 210 of file Pins.h.

◆ pin_

uint8_t able::Pin::pin_
protectedinherited

The Arduino pin connected to the button.

Definition at line 72 of file Pins.h.

◆ prevMillis_

unsigned long able::DoubleClickerPin::prevMillis_
protected

Previous millisecond count from last state change.

Definition at line 364 of file Pins.h.

◆ prevReading_

uint8_t able::DebouncedPin::prevReading_
protectedinherited

The previous pin reading, to monitor state transitions.

Definition at line 209 of file Pins.h.

◆ prevState_

uint8_t able::ClickerPin::prevState_
protectedinherited

Previous debounced reading of the pin.

Definition at line 267 of file Pins.h.

◆ stateCount_

uint8_t able::DoubleClickerPin::stateCount_
protected

Count changes in state within double-click time.

Definition at line 363 of file Pins.h.


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