Update stable version 24/05/2025 #2

Merged
rafa merged 29 commits from dev into main 2025-05-24 20:00:44 +02:00
3 changed files with 54 additions and 1 deletions
Showing only changes of commit 3cdfff0a10 - Show all commits

View File

@ -0,0 +1,31 @@
class CarSpotCOntroller {
private:
int total_spots;
int occupied_spots;
public:
CarSpotCOntroller(int default_total_spots) {
this->set_total_spots(default_total_spots);
}
int get_total_spots() {
return this->total_spots;
}
void set_total_spots(int total_spots) {
this->total_spots = total_spots;
}
int get_occupied_spots() {
return this->occupied_spots;
}
void set_occupied_spots(int occupied_spots) {
this->occupied_spots = occupied_spots;
}
void increment_occupied_spots () {
this->occupied_spots++;
}
};

View File

@ -51,4 +51,20 @@ class LCDScreen {
lcd.print(this->default_message); lcd.print(this->default_message);
} }
void display_parking_spots(int total_spots, int occupied_spots){
if (this->state != DISPLAY_PARKING_SPOTS){
this->clear();
this->state = DISPLAY_PARKING_SPOTS;
}
int free_spots = total_spots - occupied_spots;
lcd.setCursor(0, 0);
lcd.print("Occupied: ");
lcd.print(occupied_spots);
lcd.print(" / ");
lcd.print(total_spots);
lcd.setCursor(0, 1);
lcd.print("Free: ");
lcd.print(free_spots);
}
}; };

View File

@ -5,6 +5,7 @@
#include "Barrier.cpp"; #include "Barrier.cpp";
#include "DistSensor.cpp"; #include "DistSensor.cpp";
#include "LCDScreen.cpp"; #include "LCDScreen.cpp";
#include "CarSpotController.cpp";
#define ULTRASONIC_SENSOR_PIN_TRIG 11 #define ULTRASONIC_SENSOR_PIN_TRIG 11
#define ULTRASONIC_SENSOR_PIN_ECHO 12 #define ULTRASONIC_SENSOR_PIN_ECHO 12
@ -17,6 +18,7 @@ DallasTemperature temperature_sensors(&oneWire);
DistSensor dist_sensor = DistSensor(ULTRASONIC_SENSOR_PIN_TRIG, ULTRASONIC_SENSOR_PIN_ECHO, 25.0); DistSensor dist_sensor = DistSensor(ULTRASONIC_SENSOR_PIN_TRIG, ULTRASONIC_SENSOR_PIN_ECHO, 25.0);
Barrier barrier = Barrier(SERVO_PIN, 4); Barrier barrier = Barrier(SERVO_PIN, 4);
LCDScreen screen = LCDScreen(); LCDScreen screen = LCDScreen();
CarSpotCOntroller car_spot_controller = CarSpotCOntroller(24);
unsigned long current_time, sensor_last_time_activated, temperature_last_time_measured; unsigned long current_time, sensor_last_time_activated, temperature_last_time_measured;
@ -39,6 +41,7 @@ void loop() {
sensor_last_time_activated = current_time; sensor_last_time_activated = current_time;
if(barrier.is_closed()){ if(barrier.is_closed()){
barrier.open(); barrier.open();
car_spot_controller.increment_occupied_spots();
} }
} else if (!dist_sensor.is_in_range() && barrier.is_open()){ } else if (!dist_sensor.is_in_range() && barrier.is_open()){
if (current_time - sensor_last_time_activated >= barrier.open_time_seconds * 1000){ if (current_time - sensor_last_time_activated >= barrier.open_time_seconds * 1000){
@ -52,5 +55,8 @@ void loop() {
temperature_in_c = temperature_sensors.getTempCByIndex(0); temperature_in_c = temperature_sensors.getTempCByIndex(0);
} }
screen.display_temperature(temperature_in_c); //screen.display_temperature(temperature_in_c);
screen.display_parking_spots(car_spot_controller.get_total_spots(), car_spot_controller.get_occupied_spots());
} }