-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbutton.h
54 lines (45 loc) · 1.04 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
// button.h
#ifndef Button_H
#define Button_H
#include <Arduino.h>
#ifdef __STM32F1__
const WiringPinMode INTERNAL_RESISTOR = INPUT_PULLUP;
const WiringPinMode EXTERNAL_RESISTOR = INPUT;
#else
const int INTERNAL_RESISTOR = INPUT_PULLUP;
const int EXTERNAL_RESISTOR = INPUT;
#endif
class Button {
private:
int pinNumber;
int state = 0;
unsigned long longHoldThreshold;
unsigned long longHoldStartTime;
int previousPosition = HIGH;
int currentPosition = HIGH;
unsigned long lastCheck;
unsigned int checkDelay;
void getPosition();
public:
#ifdef __STM32F1__
void beginButton (int, unsigned long, unsigned int, WiringPinMode);
#else
void beginButton (int, unsigned long, unsigned int, int);
#endif
void setState(int);
int checkButton();
};
struct PairResult {
int pairStatus;
int status1;
int status2;
};
class ButtonPair {
private:
Button button1;
Button button2;
public:
void setPair(Button button1, Button button2);
PairResult checkPair();
};
#endif