Arduino Helpers master
Utility library for Arduino
IncrementButton.cpp
Go to the documentation of this file.
1#include "IncrementButton.hpp"
2
4
6 Button::State incrState = button.update();
7
8 if (incrState == Button::Released) {
9 // Button released, don't do anything
10 // This one is first to minimize overhead
11 // because most of the time, the button will
12 // be released
13 return Nothing;
14 } else if (incrState == Button::Rising) {
17 return res;
18 } else if (incrState == Button::Falling) {
19 return IncrementShort;
20 } else { // if (incrState == Button::Pressed)
21 auto now = millis();
23 // still long pressed
26 return IncrementHold;
27 }
28 } else if (button.stableTime(now) >= LONG_PRESS_DELAY) {
29 // long press starts
31 longPressRepeat = now;
32 return IncrementLong;
33 }
34 }
35 return Nothing;
36}
37
#define END_AH_NAMESPACE
#define BEGIN_AH_NAMESPACE
constexpr unsigned long LONG_PRESS_REPEAT_DELAY
The time between increments/decremnets during a long press.
Definition: Settings.hpp:87
constexpr unsigned long LONG_PRESS_DELAY
The time in milliseconds before a press is registered as a long press.
Definition: Settings.hpp:84
unsigned long stableTime(unsigned long now) const
Return the time (in milliseconds) that the button has been stable for, compared to the given time poi...
Definition: Button.cpp:50
State update()
Read the button and return its new state.
Definition: Button.cpp:11
State
An enumeration of the different states a button can be in.
Definition: Button.hpp:45
@ Rising
Input went from low to high (0,1)
Definition: Button.hpp:49
@ Falling
Input went from high to low (1,0)
Definition: Button.hpp:48
@ Released
Input went from high to high (1,1)
Definition: Button.hpp:47
State
An enumeration of the different actions to be performed by the counter.
@ Nothing
The counter must not be incremented.
@ IncrementShort
The counter must be incremented (after short press).
@ IncrementHold
The counter must be incremented (still pressed).
@ ReleasedLong
The button was released after a long press.
@ IncrementLong
The counter must be incremented (after long press).
@ ReleasedShort
The button was released after a short press.
unsigned long longPressRepeat
enum IncrementButton::@0 longPressState
State updateImplementation()