-
Notifications
You must be signed in to change notification settings - Fork 0
/
FancyButton.h
42 lines (38 loc) · 959 Bytes
/
FancyButton.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
34
35
36
37
38
39
40
41
42
/*
* FancyButton.cpp - Library for debouncing and generating long press events
* Created by Miguel Pachá, Sep 4, 2020.
*
* License: LGPL
*/
#ifndef FancyButton_h
#define FancyButton_h
#include "Arduino.h"
class FancyButton
{
public:
FancyButton(int pin);
void check();
bool press();
bool short_press();
bool long_press();
bool long_released();
volatile bool press_flag;
volatile bool short_press_flag;
volatile bool long_press_flag;
volatile bool release_long_flag;
const unsigned long LONG_PRESS_TIME = 2000;
const unsigned long debounceDelay = 50; // debounce time; increase if output flickers
private:
int _pin;
volatile bool _counting = false;
volatile bool _reading;
volatile bool _last_reading = HIGH;
volatile unsigned long _last_event;
enum button_state {
standby,
pressed,
long_pressed
};
button_state _state = standby;
};
#endif