#include <LiquidCrystal_I2C.h>
#include <ESP32Servo.h>
LiquidCrystal_I2C lcd(0x27,16,2);
Servo servo;
const int entryPIR = 13;
const int exitPIR = 16;
int parkingSlots = 5;
int inPIRVal;
int outPIRVal;
int flag1 = 1;
int flag2 = 1;
void setup() {
// put your setup code here, to run once:
pinMode(21, OUTPUT);
pinMode(22, OUTPUT);
pinMode(entryPIR, INPUT);
pinMode(exitPIR, INPUT);
Serial.begin(9600);
lcd.init();
servo.attach(32);
}
void loop() {
// put your main code here, to run repeatedly:
lcd.setCursor(0,0);
inPIRVal = digitalRead(entryPIR);
outPIRVal = digitalRead(exitPIR);
if(inPIRVal && flag1){
parkingSlots--;
servo.write(0);
lcd.print("Vacant spots: ");
lcd.print(parkingSlots);
delay(5000);
flag1 = 0;
}else if(inPIRVal == 0){
flag1 = 1;
servo.write(90);
}
if(outPIRVal && flag2){
parkingSlots++;
servo.write(0);
lcd.print("Vacant spots: ");
lcd.print(parkingSlots);
delay(5000);
flag2 = 0;
}else if(inPIRVal == 0){
flag2 = 1;
servo.write(90);
}
// lcd.print("Vacant spots: ");
// lcd.print(parkingSlots);
}