1#include <Ultrasonic.h>
2#include<LiquidCrystal_I2C.h>
3#include<Wire.h>
4LiquidCrystal_I2C lcd (0x27, 16, 2);
5Ultrasonic ultrasonic1 (13, 12);
6Ultrasonic ultrasonic2 (11, 10);
7int ledOccupied1 = 9;
8int ledFree1 = 8;
9int ledOccupied2 = 7;
10int ledFree2 = 6;
11int val1;
12int val2;
13byte SpaceA[] =
14{
15 0b11111,
16 0b10001,
17 0b10011,
18 0b10111,
19 0b11111,
20 0b10011,
21 0b10011,
22 0b10011
23};
24byte SpaceB[] =
25{
26 0b11111,
27 0b10001,
28 0b11001,
29 0b11101,
30 0b11111,
31 0b11001,
32 0b11001,
33 0b11001
34};
35byte SpaceC[] =
36{
37 0b10011,
38 0b10011,
39 0b10011,
40 0b10011,
41 0b10000,
42 0b10000,
43 0b10000,
44 0b11111
45};
46byte SpaceD[] =
47{
48 0b11001,
49 0b11001,
50 0b11001,
51 0b11001,
52 0b00001,
53 0b00001,
54 0b00001,
55 0b11111
56};
57byte NoSpaceA[] =
58{
59 0b11111,
60 0b10000,
61 0b10000,
62 0b11000,
63 0b11100,
64 0b11110,
65 0b10111,
66 0b10011
67};
68byte NoSpaceB[] =
69{
70 0b11111,
71 0b00001,
72 0b00001,
73 0b00011,
74 0b00111,
75 0b01111,
76 0b11101,
77 0b11001
78};
79byte NoSpaceC[] = {
80 0b10011,
81 0b10111,
82 0b11110,
83 0b11100,
84 0b11000,
85 0b10000,
86 0b10000,
87 0b11111
88};
89byte NoSpaceD[] = {
90 0b11001,
91 0b11101,
92 0b01111,
93 0b00111,
94 0b00011,
95 0b00001,
96 0b00001,
97 0b11111
98};
99void setup() {
100 lcd.init();
101 lcd.backlight();
102
103 lcd.createChar(1, SpaceA);
104 lcd.createChar(2, SpaceB);
105 lcd.createChar(3, SpaceC);
106 lcd.createChar(4, SpaceD);
107 lcd.createChar(5, NoSpaceA);
108 lcd.createChar(6, NoSpaceB);
109 lcd.createChar(7, NoSpaceC);
110 lcd.createChar(8, NoSpaceD);
111
112 pinMode(ledOccupied1, OUTPUT);
113 pinMode(ledFree1, OUTPUT);
114 pinMode(ledOccupied2, OUTPUT);
115 pinMode(ledFree2, OUTPUT);
116}
117
118void loop() {
119
120 val1 = ultrasonic1.Ranging(CM);
121 val2 = ultrasonic2.Ranging(CM);
122
123 if ((val1 < 10) && (val2 > 10)) {
124 digitalWrite(ledOccupied1, HIGH);
125 digitalWrite(ledFree1, LOW);
126 digitalWrite(ledOccupied2, LOW);
127 digitalWrite(ledFree2, HIGH);
128 lcd.clear();
129 lcd.write(5);
130 lcd.setCursor(1, 0);
131 lcd.write(6);
132 lcd.setCursor(0, 1);
133 lcd.write(7);
134 lcd.setCursor(1, 1);
135 lcd.write(8);
136 lcd.setCursor(7, 0);
137 lcd.write(1);
138 lcd.setCursor(8, 0);
139 lcd.write(2);
140 lcd.setCursor(7, 1);
141 lcd.write(3);
142 lcd.setCursor(8, 1);
143 lcd.write(4);
144 delay(500);
145 }
146
147 else if ((val1 > 10) && (val2 < 10)) {
148 digitalWrite(ledOccupied1, LOW);
149 digitalWrite(ledFree1, HIGH);
150 digitalWrite(ledOccupied2, HIGH);
151 digitalWrite(ledFree2, LOW);
152 lcd.clear();
153 lcd.write(1);
154 lcd.setCursor(1, 0);
155 lcd.write(2);
156 lcd.setCursor(0, 1);
157 lcd.write(3);
158 lcd.setCursor(1, 1);
159 lcd.write(4);
160 lcd.setCursor(7, 0);
161 lcd.write(5);
162 lcd.setCursor(8, 0);
163 lcd.write(6);
164 lcd.setCursor(7, 1);
165 lcd.write(7);
166 lcd.setCursor(8, 1);
167 lcd.write(8);
168 delay(500);
169 }
170
171 else if ((val1 > 10) && (val2 > 10)) {
172 digitalWrite(ledOccupied1, LOW);
173 digitalWrite(ledFree1, HIGH);
174 digitalWrite(ledOccupied2, LOW);
175 digitalWrite(ledFree2, HIGH);
176 lcd.clear();
177 lcd.write(1);
178 lcd.setCursor(1, 0);
179 lcd.write(2);
180 lcd.setCursor(0, 1);
181 lcd.write(3);
182 lcd.setCursor(1, 1);
183 lcd.write(4);
184 lcd.setCursor(7, 0);
185 lcd.write(1);
186 lcd.setCursor(8, 0);
187 lcd.write(2);
188 lcd.setCursor(7, 1);
189 lcd.write(3);
190 lcd.setCursor(8, 1);
191 lcd.write(4);
192 delay(500);
193 }
194
195 else if ((val1 < 10) && (val2 < 10)) {
196 digitalWrite(ledOccupied1, HIGH);
197 digitalWrite(ledFree1, LOW);
198 digitalWrite(ledOccupied2, HIGH);
199 digitalWrite(ledFree2, LOW);
200 lcd.clear();
201 lcd.write(5);
202 lcd.setCursor(1, 0);
203 lcd.write(6);
204 lcd.setCursor(0, 1);
205 lcd.write(7);
206 lcd.setCursor(1, 1);
207 lcd.write(8);
208 lcd.setCursor(7, 0);
209 lcd.write(5);
210 lcd.setCursor(8, 0);
211 lcd.write(6);
212 lcd.setCursor(7, 1);
213 lcd.write(7);
214 lcd.setCursor(8, 1);
215 lcd.write(8);
216 delay(500);
217 }
218 else {
219 lcd.clear();
220 digitalWrite(ledOccupied1, LOW);
221 digitalWrite(ledFree1, LOW);
222 digitalWrite(ledOccupied2, LOW);
223 digitalWrite(ledFree2, LOW);
224 }
225}
robertosecai19-
a year ago
code doesn't work