#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <Servo.h>
Servo myservo;
LiquidCrystal_I2C lcd(0x27, 16, 2);
int noOfSlot = 10;
int carInTransit = LOW;
int carInward = LOW;
int carOutard = LOW;
void setup()
{
lcd.init();
lcd.backlight();
pinMode(2, INPUT);
pinMode(3, INPUT);
lcd.setCursor(0, 0);
lcd.print("Smart Parking");
myservo.attach(6);
}
void loop()
{
delay(1000);
int pinState2 = digitalRead(2);
int pinState3 = digitalRead(3);
if (carInTransit == LOW && pinState2 == HIGH )
{
carInTransit = HIGH;
carInward = HIGH;
// OPEN Gate
myservo.write(90);
}
if (carInTransit == LOW && pinState3 == HIGH )
{
carInTransit = HIGH;
carOutard = HIGH;
// OPEN Gate
myservo.write(90);
}
if (carInward == HIGH && pinState3 == LOW && pinState2 == LOW)
{
noOfSlot = noOfSlot - 1;
carInTransit = LOW;
carInward = LOW;
}
if (carOutard == HIGH && pinState2 == LOW && pinState3 == LOW)
{
noOfSlot = noOfSlot + 1;
carInTransit = LOW;
carOutard = LOW;
}
if (noOfSlot >= 10)
{
lcd.setCursor(0, 1);
lcd.print("" + String(noOfSlot));
}
else
{
lcd.setCursor(0, 1);
lcd.print("0" + String(noOfSlot));
}
if(carInTransit==LOW){
myservo.write(0);
}
}