-
Notifications
You must be signed in to change notification settings - Fork 3
/
Code_Part_2_(Parking_Slots).ino
86 lines (69 loc) · 1.37 KB
/
Code_Part_2_(Parking_Slots).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
#include <Servo.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
Servo myservo;
#define ir_car1 5
#define ir_car2 6
#define ir_car3 7
#define ir_car4 8
int S1 = 0, S2 = 0, S3 = 0, S4 = 0;
int slot = 4;
void setup() {
Serial.begin(9600);
pinMode(ir_car1, INPUT);
pinMode(ir_car2, INPUT);
pinMode(ir_car3, INPUT);
pinMode(ir_car4, INPUT);
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print(" Car Parking ");
lcd.setCursor(0, 1);
lcd.print(" System ");
delay(3000);
lcd.clear();
Read_Sensor();
}
void loop() {
Read_Sensor();
lcd.setCursor(0, 0);
if (S1 == 1) {
lcd.print("1:Full ");
} else {
lcd.print("1:Empty");
}
lcd.setCursor(9, 0);
if (S2 == 1) {
lcd.print("2:Full ");
} else {
lcd.print("2:Empty");
}
lcd.setCursor(0, 1);
if (S3 == 1) {
lcd.print("3:Full ");
} else {
lcd.print("3:Empty");
}
lcd.setCursor(9, 1);
if (S4 == 1) {
lcd.print("4:Full ");
} else {
lcd.print("4:Empty");
}
}
void Read_Sensor() {
S1 = 0, S2 = 0, S3 = 0, S4 = 0;
if (digitalRead(ir_car1) == 0) {
S1 = 1;
}
if (digitalRead(ir_car2) == 0) {
S2 = 1;
}
if (digitalRead(ir_car3) == 0) {
S3 = 1;
}
if (digitalRead(ir_car4) == 0) {
S4 = 1;
}
}