// TUTORIAL > MIO
// 2 > 0 - led POS
// 12 > 3 - TRIG
// 13 > 2 - ECHO
// mis ficheros
#include "global.h"
#include "hc-sr04.h"
#include "leds.h"
int DISTANCIA = 0;
void setup() {
Serial.begin(9600);
setup_hcsr04();
setup_leds();
}
void loop() {
loop_leds();
// Calculamos la distancia en CM
DISTANCIA = 0.017 * readUltrasonicDistance();
// Mostramos la distancia
//Serial.print(DISTANCIA);
//Serial.println(" cm.");
// Si la distancia es menor de 20 cm enciendo el LED
if (DISTANCIA < 20) {
encender();
} else {
// Como apago por distancia, lo indico en la variable que lo controla
autoOff = 0;
apagar();
}
delay(DT); // this speeds up the simulation
}