-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsensor_prox.cpp
More file actions
41 lines (36 loc) · 1.17 KB
/
Copy pathsensor_prox.cpp
File metadata and controls
41 lines (36 loc) · 1.17 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
//Modulo modelo para la función de control para cada servo
//Se requiere un módulo de función para cada motor
//Libreria de la función
#include "sensor_prox.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"
SensorProximidad::SensorProximidad(unsigned char _pin, unsigned long _tiempoRebote) {
pin = _pin;
tiempoRebote = _tiempoRebote;
pinMode(pin, INPUT_PULLUP);
valor = HIGH;
anterior = HIGH;
estado = SUELTO;
temporizador = 0;
}
void SensorProximidad::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 SensorProximidad::leer() {
return estado;
}