-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHoldButton.h
33 lines (29 loc) · 947 Bytes
/
HoldButton.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#ifndef HoldButton_h
#define HoldButton_h
#include "Arduino.h"
#include "callback.h"
/*
Momentary button with builtin debouncing.
Calls hold_callback when held for longer than hold_duration and calls release_callback when released from a sustained press.
Written by Killian Meersman <[email protected]> 2018
*/
class HoldButton {
public:
HoldButton() {}
HoldButton(byte pin, bool pullup, unsigned long hold_duration,
Callback hold_callback = NULL, Callback release_callback = NULL, int debounce_delay = 50);
void update();
bool is_pressed();
void set_hold_callback(Callback callback);
void set_release_callback(Callback callback);
private:
byte pin;
bool pressed_mode;
bool last_state = false;
bool debounced_state = false;
unsigned long last_debounce = 0;
unsigned long hold_duration;
int debounce_delay;
Callback hold_callback, release_callback;
};
#endif