52 lines
1.5 KiB
Arduino
52 lines
1.5 KiB
Arduino
|
#include <Arduino.h>
|
||
|
#define TIME_INI 150 //Tiempo de inflado en segundos
|
||
|
#define TIME_ON_MIN 10 //Tiempo de reinflado en segundos minimo
|
||
|
#define TIME_ON_MAX 60 //Tiempo de reinflado en segundos minimo
|
||
|
#define TIME_OFF_MIN 3 //Tiempo apagado en minutos
|
||
|
#define TIME_OFF_MAX 20 //Tiempo apagado en minutos
|
||
|
|
||
|
|
||
|
#if defined(ESP32)
|
||
|
#define R1 13
|
||
|
#define R2 27
|
||
|
#define LIMIT_RES 4095
|
||
|
#else
|
||
|
#define R1 13
|
||
|
#define R2 11
|
||
|
#define LIMIT_RES 1023
|
||
|
#endif
|
||
|
#define sensorON A0
|
||
|
#define sensorOFF A1
|
||
|
|
||
|
// the setup function runs once when you press reset or power the board
|
||
|
void setup() {
|
||
|
// initialize digital pin LED_BUILTIN as an output.
|
||
|
Serial.begin(115200);
|
||
|
pinMode(R1, OUTPUT);
|
||
|
pinMode(R2, OUTPUT);
|
||
|
digitalWrite(R1, LOW);
|
||
|
digitalWrite(R2, LOW);
|
||
|
|
||
|
Serial.println("Arrancando sistema");
|
||
|
digitalWrite(R1, HIGH);
|
||
|
for(int i= 0; i<TIME_INI; i++) delay(1000);
|
||
|
digitalWrite(R1, LOW);
|
||
|
}
|
||
|
|
||
|
float distance;
|
||
|
bool flag_extra_time = false;
|
||
|
|
||
|
void loop() {
|
||
|
|
||
|
for(int i=0; i<map(analogRead(sensorOFF), 0, LIMIT_RES, TIME_OFF_MIN, TIME_OFF_MAX); i++) //Sistema apagado
|
||
|
for(int j=0; j<60; j++)
|
||
|
delay(1000);
|
||
|
digitalWrite(R1, HIGH);
|
||
|
for(int i= 0; i<map(analogRead(sensorON), 0, LIMIT_RES, TIME_ON_MIN, TIME_ON_MAX); i++) delay(1000);
|
||
|
digitalWrite(R1, LOW);
|
||
|
Serial.print(map(analogRead(sensorOFF), 0, LIMIT_RES, TIME_OFF_MIN, TIME_OFF_MAX));
|
||
|
Serial.print(" ");
|
||
|
Serial.println(map(analogRead(sensorON), 0, LIMIT_RES, TIME_ON_MIN, TIME_ON_MAX));
|
||
|
}
|
||
|
|