Create a car spot controller
This commit is contained in:
parent
35d38aeba7
commit
3cdfff0a10
31
code/CarSpotController.cpp
Normal file
31
code/CarSpotController.cpp
Normal 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++;
|
||||
}
|
||||
};
|
||||
@ -51,4 +51,20 @@ class LCDScreen {
|
||||
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);
|
||||
}
|
||||
|
||||
};
|
||||
@ -5,6 +5,7 @@
|
||||
#include "Barrier.cpp";
|
||||
#include "DistSensor.cpp";
|
||||
#include "LCDScreen.cpp";
|
||||
#include "CarSpotController.cpp";
|
||||
|
||||
#define ULTRASONIC_SENSOR_PIN_TRIG 11
|
||||
#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);
|
||||
Barrier barrier = Barrier(SERVO_PIN, 4);
|
||||
LCDScreen screen = LCDScreen();
|
||||
CarSpotCOntroller car_spot_controller = CarSpotCOntroller(24);
|
||||
|
||||
unsigned long current_time, sensor_last_time_activated, temperature_last_time_measured;
|
||||
|
||||
@ -39,6 +41,7 @@ void loop() {
|
||||
sensor_last_time_activated = current_time;
|
||||
if(barrier.is_closed()){
|
||||
barrier.open();
|
||||
car_spot_controller.increment_occupied_spots();
|
||||
}
|
||||
} else if (!dist_sensor.is_in_range() && barrier.is_open()){
|
||||
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);
|
||||
}
|
||||
|
||||
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());
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user