-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathControlButton.cpp
More file actions
117 lines (100 loc) · 2.06 KB
/
ControlButton.cpp
File metadata and controls
117 lines (100 loc) · 2.06 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//#include "Arduino.h"
#include "Bounce2.h"
#include "ControlButton.h"
ControlButton::ControlButton()
{
setup();
this->_button = Bounce();
}
ControlButton::ControlButton(byte buttonPin)
{
this->setup();
this->_button = Bounce();
this->setPin(buttonPin);
}
ControlButton::ControlButton(byte buttonPin, byte interval)
{
this->setup();
this->_interval = interval;
this->_button = Bounce();
this->setPin(buttonPin);
}
byte ControlButton::check()
{
this->_value = 0;
this->_button.update();
if (this->_button.fell()) {
boolean released = false;
elapsedMillis t = 0;
while (t < 350 && released == false) {
Serial.println(t);
this->_button.update();
if (this->_button.read() != 0) {
released = true;
this->_value = 1;
}
}
if (released == false) {
this->_value = 2;
}
Serial.println("");
}
return this->_value;
}
void ControlButton::setup()
{
this->_value = 0;
}
void ControlButton::setup(byte buttonPin)
{
this->setup();
this->setPin(buttonPin);
}
void ControlButton::setPin(byte buttonPin)
{
this->_pin = buttonPin;
if (buttonPin > 0) {
pinMode(this->_pin, INPUT_PULLUP);
this->_button.attach(this->_pin);
this->_button.interval(this->_interval);
}
}
byte ControlButton::getPin() {
return this->_pin;
}
// Most of these are just pass-thrus so that
// we are not accessing the button directly
boolean ControlButton::fell()
{
return this->_button.fell();
}
boolean ControlButton::rose()
{
return this->_button.rose();
}
void ControlButton::update() {
this->_button.update();
}
void ControlButton::setPTT(boolean val) {
this->_isPTT = val;
}
boolean ControlButton::isPTT() {
return this->_isPTT;
}
void ControlButton::setInterval(byte intv) {
this->_interval = intv;
this->_button.interval(intv);
}
byte ControlButton::getInterval() {
return this->_interval;
}
byte ControlButton::read() {
return this->_button.read();
}
void ControlButton::reset() {
this->_pin = 0;
this->_interval = 15;
this->_value = 0;
this->_type = 0;
this->_isPTT = false;
}