-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbotones.cpp
More file actions
41 lines (35 loc) · 1.07 KB
/
Copy pathbotones.cpp
File metadata and controls
41 lines (35 loc) · 1.07 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
//Modulo de control de Botones
//Libreria de la función
#include "botones.h"
//Libreria con funciones core de arduino
#include <Arduino.h>
//Libreria para usar comparación de lineas de texto
#include <string.h>
// Incluir el objeto global de servos
#include "servos_globales.h"
BotonSimple::BotonSimple(unsigned char _pin, unsigned long _tiempoRebote) {
pin = _pin;
tiempoRebote = _tiempoRebote;
pinMode(pin, INPUT_PULLUP);
valor = HIGH;
anterior = HIGH;
estado = SUELTO;
temporizador = 0;
}
void BotonSimple::actualizar() {
if (valor == digitalRead(pin)) {
temporizador = 0;
} else if (temporizador == 0) {
temporizador = millis();
} else if (millis() - temporizador >= tiempoRebote) {
valor = !valor;
}
if (anterior == LOW && valor == LOW) estado = APRETADO;
if (anterior == LOW && valor == HIGH) estado = SOLTANDOLO;
if (anterior == HIGH && valor == LOW) estado = APRETANDOLO;
if (anterior == HIGH && valor == HIGH) estado = SUELTO;
anterior = valor;
}
int BotonSimple::leer() {
return estado;
}