Arduino Helpers master
Utility library for Arduino
IncrementDecrementButtons.cpp
Go to the documentation of this file.
2
4
9
10 if (decrState == Button::Released && incrState == Button::Released) {
11 // Both released
12 } else if ((decrState == Button::Rising && incrState == Button::Released) ||
13 (incrState == Button::Rising && decrState == Button::Released) ||
14 (incrState == Button::Rising && decrState == Button::Rising)) {
15 // One released, the other rising → nothing
16 // now both released, so go to initial state
18 } else if (incrState == Button::Falling && decrState == Button::Falling) {
19 // Both falling → reset
20 // (rather unlikely, but just in case)
22 return Reset;
23 } else if (incrState == Button::Falling) {
24 if (decrState == Button::Pressed) {
25 // One pressed, the other falling → reset
27 return Reset;
28 } else {
29 // Increment falling, the other released → increment
30 return IncrementShort;
31 }
32 } else if (decrState == Button::Falling) {
33 if (incrState == Button::Pressed) {
34 // One pressed, the other falling → reset
36 return Reset;
37 } else {
38 // Decrement falling, the other released → decrement
39 return DecrementShort;
40 }
41 } else if (incrState == Button::Pressed && decrState == Button::Pressed) {
42 // Both pressed → nothing
43 } else if (longPressState != AfterReset && incrState == Button::Pressed) {
44 // Not reset and increment pressed → long press?
45 auto now = millis();
49 return IncrementHold;
50 }
53 longPressRepeat = now;
54 return IncrementLong;
55 }
56 } else if (longPressState != AfterReset && decrState == Button::Pressed) {
57 // Not reset and decrement pressed → long press?
58 auto now = millis();
62 return DecrementHold;
63 }
66 longPressRepeat = now;
67 return DecrementLong;
68 }
69 }
70 return Nothing;
71}
72
#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
@ Pressed
Input went from low to low (0,0)
Definition: Button.hpp:46
@ 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
enum IncrementDecrementButtons::@1 longPressState
State
An enumeration of the different actions to be performed by the counter.
@ DecrementLong
The counter must be decremented (after long press).
@ Nothing
The counter should not be incremented.
@ IncrementShort
The counter must be incremented (after short press).
@ IncrementHold
The counter must be incremented (still pressed).
@ DecrementHold
The counter must be decremented (still pressed).
@ DecrementShort
The counter must be decremented (after short press).
@ Reset
The counter should be reset to the initial value.
@ IncrementLong
The counter must be incremented (after long press).