DebounceSwitchRK
Public Member Functions | Protected Attributes
DebounceConfiguration Class Reference

Container for timing-related settings for switches. More...

#include <DebounceSwitchRK.h>

Inheritance diagram for DebounceConfiguration:
DebounceSwitch DebounceSwitchState

Public Member Functions

DebounceConfigurationwithDebounceMs (unsigned long ms)
 Set the debounce press and release time in milliseconds (default: 20) More...
 
DebounceConfigurationwithDebouncePressMs (unsigned long ms)
 Set the debounce press time in milliseconds (default: 20) More...
 
unsigned long getDebouncePressMs () const
 Gets the debounce time in milliseconds (default: 20)
 
DebounceConfigurationwithDebounceReleaseMs (unsigned long ms)
 Set the debounce release time in milliseconds (default: 20) More...
 
unsigned long getDebounceReleaseMs () const
 Gets the debounce time in milliseconds (default: 20)
 
DebounceConfigurationwithInterTapMs (unsigned long ms)
 Set the inter-tap time in milliseconds (default: 500) More...
 
unsigned long getInterTapMs () const
 Gets the inter-tap time in milliseconds (default: 500)
 
DebounceConfigurationwithLongPressMs (unsigned long ms)
 Set the long press duration in milliseconds (default: 3000, 3 seconds) More...
 
DebounceConfigurationwithNoLongPress ()
 Disables support for long and very long press. Only short press is returned.
 
unsigned long getLongPressMs () const
 Get the long press duration in milliseconds (default: 3000, 3 seconds)
 
DebounceConfigurationwithVeryLongPressMs (unsigned long ms)
 Set the very long press duration in milliseconds (default: 10000, 10 seconds) More...
 
DebounceConfigurationwithNoVeryLongPress ()
 Disables support for very long press. More...
 
unsigned long getVeryLongPressMs () const
 Gets the very long press duration in milliseconds (default: 10000, 10 seconds)
 
DebounceConfigurationoperator= (const DebounceConfiguration &src)
 Copy settings from another DebounceConfiguration. More...
 

Protected Attributes

unsigned long debouncePressMs = 20
 Debounce period for press in milliseconds (default: 20) More...
 
unsigned long debounceReleaseMs = 20
 Debounce period for release in milliseconds (default: 20) More...
 
unsigned long interTapMs = 500
 How long to wait for double-tap, triple-tap, etc. in milliseconds (default: 500) More...
 
unsigned long longPressMs = 3000
 How long to wait for a long press in milliseconds (default: 3000, or 3 seconds) More...
 
unsigned long veryLongPressMs = 10000
 How long to wait for a very long press in milliseconds (default: 10000, or 10 seconds) More...
 

Detailed Description

Container for timing-related settings for switches.

These are set per-switch, but you can create one of these objects and set all of the settings for multiple switches at once if you have a number of identical switches, for example all momentary switches. If you have a mix of momentary and toggle switches that require different debounce timing, you can set the settings independently.

Member Function Documentation

◆ operator=()

DebounceConfiguration & DebounceConfiguration::operator= ( const DebounceConfiguration src)

Copy settings from another DebounceConfiguration.

Parameters
srcThe settings to copy from

◆ withDebounceMs()

DebounceConfiguration& DebounceConfiguration::withDebounceMs ( unsigned long  ms)
inline

Set the debounce press and release time in milliseconds (default: 20)

Parameters
msValue to change to in milliseconds. Reasonable values are 20 to 100.

There are also methods to set the press and release time individually.

◆ withDebouncePressMs()

DebounceConfiguration& DebounceConfiguration::withDebouncePressMs ( unsigned long  ms)
inline

Set the debounce press time in milliseconds (default: 20)

Parameters
msValue to change to in milliseconds. Reasonable values are 20 to 100.

If the switch is particularly bouncy you can make this larger, but increasing it also adds to the latency for detecting button presses, so 20 is a good balance.

For toggle switches, set debouncePressMs and debounceReleaseMs to be the same value, which could be a bit larger, possibly even 100 ms for both.

◆ withDebounceReleaseMs()

DebounceConfiguration& DebounceConfiguration::withDebounceReleaseMs ( unsigned long  ms)
inline

Set the debounce release time in milliseconds (default: 20)

Parameters
msValue to change to in milliseconds. Reasonable values are 20 to 100.

The minimum is around 10 ms. It should not be larger than 100 milliseconds as it affects the latency of detecting button presses. Momentary switches usually are bouncier on release (because of the spring), so setting it a little higher may help if you are still seeing bounces.

For toggle switches, set debouncePressMs and debounceReleaseMs to be the same value, which could be a bit larger, possibly even 100 ms for both.

◆ withInterTapMs()

DebounceConfiguration& DebounceConfiguration::withInterTapMs ( unsigned long  ms)
inline

Set the inter-tap time in milliseconds (default: 500)

Parameters
msValue to change to in milliseconds. Reasonable values are 250 to 2000.

When detecting multiple taps, there needs to be a timeout from the last release before we know whether it was a single, double, or triple tap. After the inter-tap timeout occurs, we definitively know that the last tap has been made and any new tap will start over again at 1.

Making this longer makes it easier to double-tap, but it also delays the amount of time until a TAP is generated.

If you are not using double or triple tap, you can ignore this setting and only respond to the SHORT state instead of TAP. SHORT is generated after each release without consulting the inter-tap timeout.

◆ withLongPressMs()

DebounceConfiguration& DebounceConfiguration::withLongPressMs ( unsigned long  ms)
inline

Set the long press duration in milliseconds (default: 3000, 3 seconds)

Parameters
msValue to change to in milliseconds. Reasonable values are 2000 to 6000 or 0 to disable.

If the button is held down longer than long press, but shorter than very long press, then a LONG button state is generated. It also means a SHORT will not be generated.

◆ withNoVeryLongPress()

DebounceConfiguration& DebounceConfiguration::withNoVeryLongPress ( )
inline

Disables support for very long press.

By disabling VERY_LONG the states: PRESS_START, LONG, and RELEASED will be sent to the callback. PROGRESS and VERY_LONG will never be sent. This can simplify your code if you only need two press states (SHORT and LONG).

◆ withVeryLongPressMs()

DebounceConfiguration& DebounceConfiguration::withVeryLongPressMs ( unsigned long  ms)
inline

Set the very long press duration in milliseconds (default: 10000, 10 seconds)

Parameters
msValue to change to in milliseconds. Reasonable values are 2000 to 15000. Also 0 is valid as very long press disabled; see withNoVeryLongPress() or 0 to disable.

Field Documentation

◆ debouncePressMs

unsigned long DebounceConfiguration::debouncePressMs = 20
protected

Debounce period for press in milliseconds (default: 20)

The minimum is around 10 ms. It should not be larger than 100 milliseconds as it affects the latency of detecting button presses.

For toggle switches, set debouncePressMs and debounceReleaseMs to be the same value, which could be a bit larger, possibly even 100 ms for both.

◆ debounceReleaseMs

unsigned long DebounceConfiguration::debounceReleaseMs = 20
protected

Debounce period for release in milliseconds (default: 20)

The minimum is around 10 ms. It should not be larger than 100 milliseconds as it affects the latency of detecting button presses. Momentary switches usually are bouncier on release (because of the spring), so setting it a little higher may help if you are still seeing bounces.

For toggle switches, set debouncePressMs and debounceReleaseMs to be the same value, which could be a bit larger, possibly even 100 ms for both.

◆ interTapMs

unsigned long DebounceConfiguration::interTapMs = 500
protected

How long to wait for double-tap, triple-tap, etc. in milliseconds (default: 500)

Making this short reduces the latency until the TAP event is generated. However, it makes it harder to multi-tap as you have less time between release and the next press. Making it too long causes the TAP event to be very delayed, and also causes extraneous multi-taps. 500 (1/2 second) feels about right to me.

◆ longPressMs

unsigned long DebounceConfiguration::longPressMs = 3000
protected

How long to wait for a long press in milliseconds (default: 3000, or 3 seconds)

Set to 0 to disable longPress and veryLongPress.

◆ veryLongPressMs

unsigned long DebounceConfiguration::veryLongPressMs = 10000
protected

How long to wait for a very long press in milliseconds (default: 10000, or 10 seconds)

Set to 0 to disable veryLongPress.


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