#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <NewPing.h>
#define OLED_RESET -1
Adafruit_SSD1306 display(OLED_RESET);
#define TRIGGER_PIN_1 2
#define ECHO_PIN_1 3
#define TRIGGER_PIN_2 4
#define ECHO_PIN_2 5
#define TRIGGER_PIN_3 6
#define ECHO_PIN_3 7
#define MAX_DISTANCE 200
#define OCCUPIED_THRESHOLD 20 // Threshold distance to consider a spot occupied
NewPing sonar1(TRIGGER_PIN_1, ECHO_PIN_1, MAX_DISTANCE);
NewPing sonar2(TRIGGER_PIN_2, ECHO_PIN_2, MAX_DISTANCE);
NewPing sonar3(TRIGGER_PIN_3, ECHO_PIN_3, MAX_DISTANCE);
void setup() {
Serial.begin(9600);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Address 0x3C for 128x32
display.display();
delay(2000); // Delay for 2 seconds
display.clearDisplay();
}
void loop() {
delay(50); // Delay for 50 milliseconds
unsigned int distance1 = sonar1.ping_cm();
unsigned int distance2 = sonar2.ping_cm();
unsigned int distance3 = sonar3.ping_cm();
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
// Display status for Parking Spot 1
if (distance1 < OCCUPIED_THRESHOLD) {
display.println("P1 : Occupied");
} else {
display.println("P1 : Empty");
}
// Display status for Parking Spot 2
if (distance2 < OCCUPIED_THRESHOLD) {
display.println("P2 : Occupied");
} else {
display.println("P2 : Empty");
}
// Display status for Parking Spot 3
if (distance3 < OCCUPIED_THRESHOLD) {
display.println("P3 : Occupied");
} else {
display.println("P3 : Empty");
}
display.display();
}