-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathButtonConfig.ino
52 lines (46 loc) · 991 Bytes
/
ButtonConfig.ino
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
static unsigned long contaTempo = 0;
static int contaVezes = 0;
const int limiteVezes = 7;
const int intervaloTempo = 300;
static bool buttonPressed = false;
void resetDevice() {
ESP.restart();
}
void configButton() {
pinMode(BUTTON, INPUT);
digitalWrite(BUTTON, HIGH);
contaTempo = millis();
}
bool checkButton()
{
if (contaVezes >= limiteVezes) {
buttonPressed = false;
contaVezes = 0;
contaTempo = millis();
return true;
}
if (!digitalRead(BUTTON) && contaTempo < millis()) {
buttonPressed = true;
atualizaTempo();
contaVezes++;
}
else if (digitalRead(BUTTON) && contaTempo > millis()) {
contaVezes = 0;
atualizaTempo();
}
if (digitalRead(BUTTON) && buttonPressed) {
buttonPressed = false;
contaVezes = 0;
contaTempo = millis();
if (relayStatus) {
turnOffRelay();
}
else {
turnOnRelay();
}
}
return false;
}
void atualizaTempo() {
contaTempo = millis() + intervaloTempo;
}