13 volatile bool _inputFlag =
false;
14 bool _changeFlag =
false;
16 bool _pressedFlag =
false;
17 bool _holdFlag =
false;
19 unsigned long _previousTimer;
21 int _clickInterval = 1000;
22 int _holdInterval = 1000;
23 int _repeatInterval = 1000;
25 void (*_cb)(
Button*, uint8_t, bool);
28 return digitalRead(_pin);
31 void _setClickInterval(
int x) {
35 void _setHoldInterval(
int x) {
39 void _setRepeatInterval(
int x) {
55 Button(
int pin,
int id = 99) : _pin(pin), _id(id) {
56 pinMode(_pin, INPUT_PULLUP);
58 _previousTimer = millis();
62 attachInterrupt(_pin,
function, CHANGE);
78 return _clickInterval;
86 return _repeatInterval;
90 unsigned long timer = millis();
91 unsigned long deltaTime = timer - _previousTimer;
94 if (_inputFlag ==
true) {
99 && _pressedFlag ==
false) {
101 _previousTimer = timer;
106 }
else if (_state == HIGH
107 && deltaTime < _clickInterval
108 && _holdFlag ==
false) {
109 _pressedFlag =
false;
110 _previousTimer = timer;
115 }
else if (_state == HIGH) {
116 _pressedFlag =
false;
118 _previousTimer = timer;
126 && deltaTime > _holdInterval
127 && _holdFlag ==
false) {
129 _previousTimer = timer;
134 }
else if (_state == LOW
135 && deltaTime > _repeatInterval
136 && _holdFlag ==
true) {
137 _previousTimer = timer;