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

Debounced pin class that remembers the previous debounced state. More...

#include <Pins.h>

+ Inheritance diagram for able::ClickerPin:

Static Public Member Functions

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

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

Debounced pin class that remembers the previous debounced state.

This allows clicks (a combination of press then release) to be identified. This class extends the basic DebouncedPin class to add the previous state.

Definition at line 218 of file Pins.h.

Constructor & Destructor Documentation

◆ ClickerPin()

able::ClickerPin::ClickerPin ( 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 231 of file Pins.h.

Member Function Documentation

◆ 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::ClickerPin::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 252 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.

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

◆ 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_
protected

Previous debounced reading of the pin.

Definition at line 267 of file Pins.h.


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