/////// Librerias /////
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <ESP32Servo.h>
/////// Parametros de configuracion ////
LiquidCrystal_I2C lcd (0x27,16,2);
Servo servopoton ;
int Fase = 1;
int Cantidad =12;
//////// Infrarrojo de entrada
unsigned long TA01 = 0;
int Estado= 0;
int IRE = 0;
int IR_entrada (int pin){
pinMode(pin, INPUT_PULLUP);
if ((millis()-TA01) == 500){
TA01 = millis();
if ((digitalRead(pin))==LOW){ Estado = 1; }
else{Estado = 0;}
return Estado;
}
}
//////// Infrarrojo de Salida
unsigned long TA02 = 0;
int Estado02= 0;
int IRS = 0;
int IR_Salida (int pin){
pinMode(pin, INPUT_PULLUP);
if ((millis()-TA02) == 500){
TA02 = millis();
if ((digitalRead(pin))==LOW){ Estado02 = 1; }
else{Estado02 = 0;}
return Estado02;
}
}
void setup() {
Serial.begin(9600);
lcd.init();
lcd.setCursor(0,0);
lcd.clear();
lcd.backlight();
lcd.print("Inicializando");
servopoton.attach(42);
servopoton.write(90);
delay(1000);
servopoton.write(0);
lcd.clear();
}
void loop() {
IRE = IR_entrada(33);
IRS = IR_Salida(41);
/*
lcssalida.clear();
lcssalida.setCursor(0,0);
lcssalida.print (String("IRE = ") +IRE);
lcssalida.setCursor(0,1);
lcssalida.print (String("IRS = ") +IRS);
*/
////// Entrada
if ((IRE ==1)&&(IRS ==0)&& (Fase == 1)){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Bienvenido");
lcd.setCursor(0,1);
lcd.print(String("Parq. Disp. ")+ Cantidad);
delay(200);
servopoton.write(90);
Fase = 2;
Serial.print(Fase);
}
if ((IRS ==1)&&(Fase ==2)){ ////No abia espesificado la fase 2
Cantidad = Cantidad-1;
Fase = 3;
Serial.print(Fase);
}
if ((IRE ==0)&&(IRS ==0)&& (Fase == 3)){
servopoton.write(0);
lcd.setCursor(0,1);
lcd.print(String("Parq. Disp. ")+ Cantidad);
delay(100);
lcd.clear();
Fase = 1;
Serial.print(Fase);
}
/////////
if ((IRE ==0)&&(IRS ==1)&& (Fase == 1)){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Feliz Viaje");
lcd.setCursor(0,1);
lcd.print(String("Parq. Disp. ")+ Cantidad);
delay(200);
servopoton.write(90);
Fase = 4;
Serial.print(Fase);
}
if ((IRE ==1)&&(Fase ==4)){ ////No abia espesificado la fase 2
Cantidad = Cantidad+1;
Fase = 5;
Serial.print(Fase);
}
if ((IRE ==0)&&(IRS ==0)&& (Fase == 5)){
servopoton.write(0);
lcd.setCursor(0,1);
lcd.print(String("Parq. Disp. ")+ Cantidad);
delay(100);
lcd.clear();
Fase = 1;
Serial.print(Fase);
}
}
Loading
esp32-s2-devkitm-1
esp32-s2-devkitm-1