/*
Controlling a servo position using a potentiometer (variable resistor)
by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>
modified on 8 Nov 2013
by Scott Fitzgerald
http://www.arduino.cc/en/Tutorial/Knob
*/
#include <Servo.h>
#include <LiquidCrystal.h>
Servo myservo; // create servo object to control a servo
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
int Slot = 4; //Enter Total number of parking Slots
int flag1 = 0;
int flag2 = 0;
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
myservo.write(180);
pinMode(A0, INPUT_PULLUP);
pinMode(A1, INPUT_PULLUP);
lcd.print(" PARKING SYSTEM ");
delay (2000);
lcd.clear();
}
void loop() {
// Entry Red
if(!digitalRead(A0) && flag1==0){
if(Slot>0){
flag1=1;
if(flag2==0){
myservo.write(90);
Slot = Slot-1;
}
}else {
lcd.print(" Parking Full ");
delay (3000);
lcd.clear();
}
}
// Exit Blue
if(!digitalRead(A1) && flag2 == 0){
flag2 = 1;
if (flag1 == 0){
myservo.write(90);
Slot = Slot+1;
}
}
if (flag1 == 1 && flag2 == 1){
delay (1000);
myservo.write(180);
flag1=0, flag2=0;
lcd.print(Slot);
delay (1000);
lcd.clear();
}
}