Ring buzzer when parking lot is full

This commit is contained in:
rafa 2025-05-24 00:42:49 +01:00
parent 4ece705c29
commit 6554a14a77
2 changed files with 18 additions and 6 deletions

View File

@ -28,4 +28,8 @@ class CarSpotCOntroller {
void increment_occupied_spots () { void increment_occupied_spots () {
this->occupied_spots++; this->occupied_spots++;
} }
bool is_full() {
return this->occupied_spots == this->total_spots;
}
}; };

View File

@ -19,9 +19,9 @@ OneWire oneWire(TEMP_SENSOR_PIN);
DallasTemperature temperature_sensors(&oneWire); 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, 2);
LCDScreen screen = LCDScreen(); LCDScreen screen = LCDScreen();
CarSpotCOntroller car_spot_controller = CarSpotCOntroller(24); CarSpotCOntroller car_spot_controller = CarSpotCOntroller(2);
JoySitkController joystick = JoySitkController(JOYSTICK_X_PIN, JOYSTICK_Y_PIN); JoySitkController joystick = JoySitkController(JOYSTICK_X_PIN, JOYSTICK_Y_PIN);
unsigned long current_time, sensor_last_time_activated, temperature_last_time_measured, joystick_last_time_activated; unsigned long current_time, sensor_last_time_activated, temperature_last_time_measured, joystick_last_time_activated;
@ -44,8 +44,12 @@ void loop() {
if (dist_sensor.is_in_range()){ if (dist_sensor.is_in_range()){
sensor_last_time_activated = current_time; sensor_last_time_activated = current_time;
if(barrier.is_closed()){ if(barrier.is_closed()){
barrier.open(); if (!car_spot_controller.is_full()){
car_spot_controller.increment_occupied_spots(); barrier.open();
car_spot_controller.increment_occupied_spots();
}else{
tone(3, 262, 500);
}
} }
} 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){
@ -64,15 +68,19 @@ void loop() {
if (joystick.is_moving_right() && current_time - joystick_last_time_activated >= 250){ if (joystick.is_moving_right() && current_time - joystick_last_time_activated >= 250){
joystick_last_time_activated = current_time; joystick_last_time_activated = current_time;
screen.set_state((screen.get_next_state())); screen.set_state((screen.get_next_state()));
} }
if (joystick.is_moving_left() && current_time - joystick_last_time_activated >= 250){ if (joystick.is_moving_left() && current_time - joystick_last_time_activated >= 250){
joystick_last_time_activated = current_time; joystick_last_time_activated = current_time;
screen.set_state(screen.get_previous_state()); screen.set_state(screen.get_previous_state());
} }
screen.display(temperature_in_c,car_spot_controller.get_total_spots(), car_spot_controller.get_occupied_spots()); screen.display(temperature_in_c,car_spot_controller.get_total_spots(), car_spot_controller.get_occupied_spots());
} }