-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservo
59 lines (47 loc) · 1 KB
/
servo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <LiquidCrystal.h>
#include <Servo.h>
Servo myservo;
int IR1 = 7;
int IR2 = 9;
int Slot = 6; //Enter Total number of parking Slots
int flag1 = 0;
int flag2 = 0;
int pos = 0;
int Contrast=100;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
// put your setup code here, to run once:
pinMode(IR1, INPUT);
pinMode(IR2, INPUT);
analogWrite(6,Contrast);
lcd.begin(16, 2);
myservo.attach(8);
Serial.begin(9600);
}
void loop() {
if(digitalRead (IR1) == LOW && flag1==0){
if(Slot>0){flag1=1;
if(flag2==0){myservo.write(0); Slot = Slot-1;}
}else{
lcd.setCursor (0,0);
lcd.print(" SORRY :( ");
lcd.setCursor (0,1);
lcd.print(" Parking Full ");
delay (3000);
lcd.clear();
}
}
if(digitalRead (IR2) == LOW && flag2==0){flag2=1;
if(flag1==0){myservo.write(0); Slot = Slot+1;}
}
if(flag1==1 && flag2==1){
delay (1000);
myservo.write(100);
flag1=0, flag2=0;
}
lcd.setCursor (0,0);
lcd.print(" WELCOME! ");
lcd.setCursor (0,1);
lcd.print("Slot Left: ");
lcd.print(Slot);
}