-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbutton.h
65 lines (60 loc) · 1.48 KB
/
button.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#ifndef BUTTON_H
#define BUTTON_H
class buttonCore {
public:
buttonCore();
virtual buttonCore* get_next_button();
virtual void set_next_button(buttonCore &next_button);
virtual uint8_t read();
private:
buttonCore *_next_button;
};
class button : public buttonCore {
public:
button(uint8_t pin,
uint8_t return_value=1, // return value when pressed
int debounce_delay=50, // 50 ms
int repeat_delay=1000, // 1000 ms
int repeat_rate=4); // 4 repeats per second
uint8_t state();
uint8_t read();
private:
uint8_t pin;
uint8_t last_state;
uint8_t last_stable_state;
unsigned long last_debounce_time;
unsigned long last_query_time;
unsigned long returned_state_time;
int debounce_delay;
uint8_t repeating;
int repeat_delay;
int repeat_rate;
uint8_t return_value;
};
class rotaryEncoder : public buttonCore {
public:
rotaryEncoder(uint8_t pin_A,
uint8_t pin_B,
uint8_t return_value_up=1,
uint8_t return_value_down=1);
~rotaryEncoder();
uint8_t read();
private:
button *A;
button *B;
uint8_t last_state_A;
uint8_t last_state_B;
uint8_t last_state;
uint8_t return_value_up;
uint8_t return_value_down;
};
class buttonsReader {
public:
buttonsReader();
void add_button(buttonCore &new_button);
uint8_t read();
private:
buttonCore *_first;
buttonCore *_last;
};
#endif