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

Debouned Pin class. More...

#include <Pins.h>

+ Inheritance diagram for able::DebouncedPin:

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

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

Debouned Pin class.

Manages making reliable readings from an input pin. The readPin() method manages debouncing the pin readings. You cannot use this class directly. Use one of the Button sub-classes instead.

Definition at line 81 of file Pins.h.

Constructor & Destructor Documentation

◆ DebouncedPin()

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

Protected constructor used by sub-classes.

Use a 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 134 of file Pins.h.

Member Function Documentation

◆ debounceTime()

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

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 ( )
inlinestatic

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 ( )
inlinestatic

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::DebouncedPin::readPin ( )
inlineprotected

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

In order to save memory, virtual functions are not used (which can consume almost 1K of memory to deal with). Runtime polymorphism is not required, so avoiding virtual functions saves memory.

Definition at line 155 of file Pins.h.

◆ setDebounceTime()

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

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)
inlinestatic

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)
inlinestatic

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
staticprotected

Time required to debounce all input pins.

Definition at line 205 of file Pins.h.

◆ heldTime_

uint16_t able::DebouncedPin::heldTime_ = 1000
staticprotected

Time required for button to be held.

Definition at line 206 of file Pins.h.

◆ idleTime_

uint32_t able::DebouncedPin::idleTime_ = 60000
staticprotected

Time required for button to be idle.

Definition at line 207 of file Pins.h.

◆ millisStart_

unsigned long able::DebouncedPin::millisStart_
protected

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

The previous pin reading, to monitor state transitions.

Definition at line 209 of file Pins.h.


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