Serial Wombat Arduino Library
Public Member Functions | Public Attributes | List of all members
SerialWombatButtonCounter Class Reference

A class that runs on top of SerialWombaAbstractButton to increment or decrement a variable based on a button. More...

#include <SerialWombatDebouncedInput.h>

Public Member Functions

 SerialWombatButtonCounter (SerialWombatAbstractButton &serialWombatDebouncedInput)
 Constructor for SerialWombatButtonCounter. More...
 
void begin (long *variableToIncrement, long slowIncrement=1, unsigned long slow_mS_betweenIncrements=250, uint16_t slowToMediumTransition_mS=1000, long mediumIncrement=1, unsigned long medium_mS_betweenIncrements=100, uint16_t mediumToFastTransition_mS=1000, long fastIncrement=1, unsigned long fast_mS_betweenIncrements=50)
 
bool update ()
 Called periodically to query the SerialWombatDebouncedInput and update the variable. More...
 

Public Attributes

long highLimit = LONG_MAX
 The variable will not increment above this limit. More...
 
long lowLimit = LONG_MIN
 The variable will not decrement below this limit. More...
 

Detailed Description

A class that runs on top of SerialWombaAbstractButton to increment or decrement a variable based on a button.

This class runs on top of a SerialWombaAbstractButton input. It is passed a variable reference in its begin call. The update() method is then called periodically. This method will look at how many times the debounced input has transitioned since the last call, and also if the input is currently pressed and for how long.

A high limit and low limit can be set which keeps the variable from exceeing those bounds.

Times can be specified for button hold that allows the variable to be incremented at varying rates for short, medium, and long holds.

See the example sw4b_ard_Debounce2 distributed with the Serial Wombat Arduino Library and in the video

https://youtu.be/_EKlrEVaEhg

for an example.

Constructor & Destructor Documentation

◆ SerialWombatButtonCounter()

SerialWombatButtonCounter::SerialWombatButtonCounter ( SerialWombatAbstractButton serialWombatDebouncedInput)
inline

Constructor for SerialWombatButtonCounter.

Parameters
serialWombatDebouncedInputA pointer to an already initialized SerialWombatDebouncedInput, SerialWombatMatrixButton or digitally configured SerialWombat18CapTouch

Member Function Documentation

◆ begin()

void SerialWombatButtonCounter::begin ( long *  variableToIncrement,
long  slowIncrement = 1,
unsigned long  slow_mS_betweenIncrements = 250,
uint16_t  slowToMediumTransition_mS = 1000,
long  mediumIncrement = 1,
unsigned long  medium_mS_betweenIncrements = 100,
uint16_t  mediumToFastTransition_mS = 1000,
long  fastIncrement = 1,
unsigned long  fast_mS_betweenIncrements = 50 
)
inline

Initializes the SerialWombatButtonCounter

Parameters
variableToIncrementA pointer to a signed long integer
slowIncrementthe amount that the variable should increment (or decrement if negative) per increment
slow_mS_betweenIncrementshow often an increment should happen in slow mode
slowToMediumTransition_mShow long to stay in slow mode before switching to medium mode
mediumIncrementthe amount that the variable should increment (or decrement if negative) per increment
medium_mS_betweenIncrementshow often an increment should happen in medium mode
mediumToFastTransition_mShow long after the initail button press start until switching to Fast mode
fastIncrementthe amount that the variable should increment (or decrement if negative) per increment
fast_mS_betweenIncrementshow often an increment should happen in fast mode

◆ update()

bool SerialWombatButtonCounter::update ( )
inline

Called periodically to query the SerialWombatDebouncedInput and update the variable.

Member Data Documentation

◆ highLimit

long SerialWombatButtonCounter::highLimit = LONG_MAX

The variable will not increment above this limit.

◆ lowLimit

long SerialWombatButtonCounter::lowLimit = LONG_MIN

The variable will not decrement below this limit.