AceButton  1.10.0
An adjustable, compact, event-driven button library for Arduino.
Public Member Functions | Protected Member Functions | Friends | List of all members
ace_button::LadderButtonConfig Class Reference

A ButtonConfig that handles multiple buttons using a resistor ladder. More...

#include <LadderButtonConfig.h>

Inheritance diagram for ace_button::LadderButtonConfig:
Inheritance graph
[legend]
Collaboration diagram for ace_button::LadderButtonConfig:
Collaboration graph
[legend]

Public Member Functions

 LadderButtonConfig (uint8_t pin, uint8_t numLevels, const uint16_t levels[], uint8_t numButtons, AceButton *const buttons[], uint8_t defaultReleasedState=HIGH)
 Constructor. More...
 
int readButton (uint8_t pin) override
 Return state of the button corresponding to the virtual 'pin' number. More...
 
void checkButtons () const
 Read the single mPin once, calculate the virtual pin number of the pressed button (if any), then call each button's checkState() method to trigger any events. More...
 
uint8_t getNoButtonPin () const
 The virtual button pin number corresponding to "no button" pressed.
 
- Public Member Functions inherited from ace_button::ButtonConfig
 ButtonConfig ()=default
 Constructor.
 
virtual ~ButtonConfig ()=default
 If the ButtonConfig is created and deleted on the heap, a virtual destructor is technically required by the C++ language to prevent memory leaks. More...
 
uint16_t getDebounceDelay () const
 Milliseconds to wait for debouncing.
 
uint16_t getClickDelay () const
 Milliseconds to wait for a possible click.
 
uint16_t getDoubleClickDelay () const
 Milliseconds between the first and second click to register as a double-click.
 
uint16_t getLongPressDelay () const
 Milliseconds for a long press event.
 
uint16_t getRepeatPressDelay () const
 Milliseconds that a button needs to be Pressed down before the start of the sequence of RepeatPressed events. More...
 
uint16_t getRepeatPressInterval () const
 Milliseconds between two successive RepeatPressed events.
 
uint16_t getHeartBeatInterval () const
 Milliseconds between two successive HeartBeat events.
 
void setDebounceDelay (uint16_t debounceDelay)
 Set the debounceDelay milliseconds.
 
void setClickDelay (uint16_t clickDelay)
 Set the clickDelay milliseconds.
 
void setDoubleClickDelay (uint16_t doubleClickDelay)
 Set the doubleClickDelay milliseconds.
 
void setLongPressDelay (uint16_t longPressDelay)
 Set the longPressDelay milliseconds.
 
void setRepeatPressDelay (uint16_t repeatPressDelay)
 Set the repeatPressDelay milliseconds.
 
void setRepeatPressInterval (uint16_t repeatPressInterval)
 Set the repeatPressInterval milliseconds.
 
void setHeartBeatInterval (uint16_t heartBeatInterval)
 Set the heartBeatInterval milliseconds.
 
virtual unsigned long getClock ()
 Return the milliseconds of the internal clock. More...
 
bool isFeature (FeatureFlagType features) const
 Check if the given features are enabled.
 
void setFeature (FeatureFlagType features)
 Enable the given features.
 
void clearFeature (FeatureFlagType features)
 Disable the given features.
 
void resetFeatures ()
 Disable all (externally visible) features. More...
 
EventHandler getEventHandler () const ACE_BUTTON_DEPRECATED
 Return the eventHandler function pointer. More...
 
void dispatchEvent (AceButton *button, uint8_t eventType, uint8_t buttonState) const
 Dispatch the event to the handler. More...
 
void setEventHandler (EventHandler eventHandler)
 Install the EventHandler function pointer. More...
 
void setIEventHandler (IEventHandler *eventHandler)
 Install the IEventHandler object pointer. More...
 

Protected Member Functions

virtual uint8_t getVirtualPin () const
 Return the virtual pin number corresponding to current state of the ADC as returned by the analogRead() function. More...
 

Friends

class ::LadderButtonConfig_extractIndex
 

Additional Inherited Members

- Public Types inherited from ace_button::ButtonConfig
typedef uint16_t FeatureFlagType
 Type of the feature flag. More...
 
typedef void(* EventHandler) (AceButton *button, uint8_t eventType, uint8_t buttonState)
 The event handler signature. More...
 
- Static Public Member Functions inherited from ace_button::ButtonConfig
static ButtonConfiggetSystemButtonConfig ()
 Return a pointer to the singleton instance of the ButtonConfig which is attached to all AceButton instances by default.
 
- Static Public Attributes inherited from ace_button::ButtonConfig
static const uint16_t kDebounceDelay = 20
 Default milliseconds returned by getDebounceDelay().
 
static const uint16_t kClickDelay = 200
 Default milliseconds returned by getClickDelay().
 
static const uint16_t kDoubleClickDelay = 400
 Default milliseconds returned by getDoubleClickDelay().
 
static const uint16_t kLongPressDelay = 1000
 Default milliseconds returned by getLongPressDelay().
 
static const uint16_t kRepeatPressDelay = 1000
 Default milliseconds returned by getRepeatPressDelay().
 
static const uint16_t kRepeatPressInterval = 200
 Default milliseconds returned by getRepeatPressInterval().
 
static const uint16_t kHeartBeatInterval = 5000
 Default milliseconds returned by getHeartBeatInterval().
 
static const FeatureFlagType kFeatureClick = 0x01
 Flag to activate the AceButton::kEventClicked event.
 
static const FeatureFlagType kFeatureDoubleClick = 0x02
 Flag to activate the AceButton::kEventDoubleClicked event. More...
 
static const FeatureFlagType kFeatureLongPress = 0x04
 Flag to activate the AceButton::kEventLongPress event.
 
static const FeatureFlagType kFeatureRepeatPress = 0x08
 Flag to activate the AceButton::kEventRepeatPressed event.
 
static const FeatureFlagType kFeatureSuppressAfterClick = 0x10
 Flag to suppress kEventReleased after a kEventClicked.
 
static const FeatureFlagType kFeatureSuppressAfterDoubleClick = 0x20
 Flag to suppress kEventReleased after a kEventDoubleClicked. More...
 
static const FeatureFlagType kFeatureSuppressAfterLongPress = 0x40
 Flag to suppress kEventReleased after a kEventLongPressed.
 
static const FeatureFlagType kFeatureSuppressAfterRepeatPress = 0x80
 Flag to suppress kEventReleased after a kEventRepeatPressed.
 
static const FeatureFlagType kFeatureSuppressClickBeforeDoubleClick = 0x100
 Flag to suppress kEventClicked before a kEventDoubleClicked. More...
 
static const FeatureFlagType kFeatureHeartBeat = 0x200
 Flag to enable periodic kEventHeartBeat.
 
static const FeatureFlagType kInternalFeatureIEventHandler = 0x8000
 Internal flag to indicate that mEventHandler is an IEventHandler object pointer instead of an EventHandler function pointer.
 
static const FeatureFlagType kFeatureSuppressAll
 Convenience flag to suppress all suppressions. More...
 

Detailed Description

A ButtonConfig that handles multiple buttons using a resistor ladder.

Definition at line 40 of file LadderButtonConfig.h.

Constructor & Destructor Documentation

◆ LadderButtonConfig()

ace_button::LadderButtonConfig::LadderButtonConfig ( uint8_t  pin,
uint8_t  numLevels,
const uint16_t  levels[],
uint8_t  numButtons,
AceButton *const  buttons[],
uint8_t  defaultReleasedState = HIGH 
)

Constructor.

Parameters
pinthe analog pin where the buttons and resistors are connected
numLevelsnumber of voltage levels from the ADC, must be greater than numButtons
levelsan array of expected outputs of the ADC at each level. These values must be monotonically increasing. level[0] will probably be 0, corresponding to button[0] pulling down to 0V, and level[numLevels-1] is the maximum value of the ADC, corresponding to no-button pressed. It will be 1023 for a 10-bit ADC, and 4095 for a 12-bit ADC.
numButtonsnumber buttons on the ladder
buttonsarray of AceButton instances which are attached to the ladder
defaultReleasedStatestate of the encoder bit when the button is in the released state. For a pull-up wiring, the state of the pin is HIGH when the button is released.

Definition at line 30 of file LadderButtonConfig.cpp.

Member Function Documentation

◆ checkButtons()

void ace_button::LadderButtonConfig::checkButtons ( ) const

Read the single mPin once, calculate the virtual pin number of the pressed button (if any), then call each button's checkState() method to trigger any events.

This is more efficient than calling the check() of each AceButton, which in turn, calls LadderButtonConfig::readButton() for each button.

Warning: This method is often called from the global loop() function. But on ESP8266, this method must not be called too quickly, otherwise it triggers a bug which causes the WiFi to disconnect (see https://github.com/esp8266/Arduino/issues/1634 and https://github.com/esp8266/Arduino/issues/5083). You must rate-limit the calls to this method to ~5 milliseconds. See examples/LadderButtons/LadderButtons.ino for an example of how to do that.

Definition at line 58 of file LadderButtonConfig.cpp.

◆ getVirtualPin()

uint8_t ace_button::LadderButtonConfig::getVirtualPin ( ) const
protectedvirtual

Return the virtual pin number corresponding to current state of the ADC as returned by the analogRead() function.

When no button is pressed, this returns (numLevels - 1), which does not correspond to any valid button.

Definition at line 74 of file LadderButtonConfig.cpp.

◆ readButton()

int ace_button::LadderButtonConfig::readButton ( uint8_t  pin)
overridevirtual

Return state of the button corresponding to the virtual 'pin' number.

LOW means that the corresponding encoded virtual pin was pushed.

This method is not expected to be used. Use the checkButtons() method instead for this class.

Reimplemented from ace_button::ButtonConfig.

Definition at line 53 of file LadderButtonConfig.cpp.


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