-
Notifications
You must be signed in to change notification settings - Fork 0
/
park.ino
119 lines (100 loc) · 2.79 KB
/
park.ino
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include <Servo.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F, 20, 4);
#define IR_ENTRY 2
#define IR_EXIT 4
#define SERVO_PIN 3
const int slotSensors[6] = {5, 6, 7, 8, 9, 10};
int slotStatus[6] = {0, 0, 0, 0, 0, 0};
int availableSlots = 6;
bool entryFlag = false, exitFlag = false;
Servo barrierServo;
void displaySlots() {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Available Slots: ");
lcd.print(availableSlots);
for (int i = 0; i < 6; i++) {
lcd.setCursor((i % 2) * 10, 1 + (i / 2));
lcd.print("Slot");
lcd.print(i + 1);
lcd.print(":");
lcd.print(slotStatus[i] == 1 ? "Full " : "Empty");
}
}
void updateSlotStatus() {
for (int i = 0; i < 6; i++) {
slotStatus[i] = (digitalRead(slotSensors[i]) == LOW) ? 1 : 0;
}
availableSlots = 6 - countOccupiedSlots();
}
int countOccupiedSlots() {
int count = 0;
for (int i = 0; i < 6; i++) {
if (slotStatus[i] == 1) count++;
}
return count;
}
void setup() {
Serial.begin(9600);
barrierServo.attach(SERVO_PIN);
barrierServo.write(90);
pinMode(IR_ENTRY, INPUT);
pinMode(IR_EXIT, INPUT);
for (int i = 0; i < 6; i++) {
pinMode(slotSensors[i], INPUT);
}
lcd.init();
lcd.backlight();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("SMART PARKING");
lcd.setCursor(0, 1);
lcd.print("SYSTEMS..!");
delay(5000);
lcd.clear();
updateSlotStatus();
}
void loop() {
displaySlots();
if (availableSlots == 0 && digitalRead(IR_ENTRY) == LOW && !entryFlag && !exitFlag) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("SORRY PARKING");
lcd.setCursor(0, 1);
lcd.print("IS FULL :)");
barrierServo.write(90);
return;
}
if (digitalRead(IR_ENTRY) == LOW && !entryFlag && !exitFlag) {
entryFlag = true;
barrierServo.write(180);
lcd.setCursor(0, 0);
lcd.print("Vehicle Entering...");
delay(500);
}
if (entryFlag && digitalRead(IR_EXIT) == LOW) {
barrierServo.write(90);
lcd.setCursor(0, 0);
lcd.print("Gate Closing...");
delay(1500);
entryFlag = false;
}
if (digitalRead(IR_EXIT) == LOW && !exitFlag && !entryFlag) {
exitFlag = true;
barrierServo.write(180);
lcd.setCursor(0, 0);
lcd.print("Vehicle Exiting...");
delay(500);
}
if (exitFlag && digitalRead(IR_ENTRY) == LOW) {
barrierServo.write(90);
lcd.setCursor(0, 0);
lcd.print("Gate Closing...");
delay(1500);
exitFlag = false;
updateSlotStatus();
delay(500);
}
}