diff --git a/code/code.ino b/code/code.ino index 451aa6e..43b9502 100644 --- a/code/code.ino +++ b/code/code.ino @@ -7,6 +7,7 @@ #include "LCDScreen.cpp"; #include "CarSpotController.cpp"; #include "JoyStickController.cpp"; +#include "ButtonController.cpp"; #define PARK_SLOTS 3 #define ULTRASONIC_SENSOR_PIN_TRIG 11 @@ -16,6 +17,7 @@ #define JOYSTICK_X_PIN A1 #define JOYSTICK_Y_PIN A0 #define BUZZER_PIN 3 +#define BUTTON_PIN 8 OneWire oneWire(TEMP_SENSOR_PIN); DallasTemperature temperature_sensors(&oneWire); @@ -25,8 +27,10 @@ Barrier barrier = Barrier(SERVO_PIN, 2); LCDScreen screen = LCDScreen(); CarSpotController car_spot_controller = CarSpotController(2); JoystickController joystick = JoystickController(JOYSTICK_X_PIN, JOYSTICK_Y_PIN); +ButtonController button = ButtonController(BUTTON_PIN); -unsigned long current_time, sensor_last_time_readed, sensor_last_time_activated, temperature_last_time_measured, joystick_last_time_activated, joystick_last_time_readed, screen_last_time_updated; + +unsigned long current_time, sensor_last_time_readed, barrier_last_time_opened, temperature_last_time_measured, joystick_last_time_activated, joystick_last_time_readed, screen_last_time_updated; float temperature_in_c = 0; @@ -36,16 +40,28 @@ void setup() { barrier.configure_pins(); temperature_sensors.begin(); joystick.configure_pins(); + button.configure_pins(); screen.init(); } void loop() { + current_time = millis(); + button.read(); + + if (button.is_pressed()){ + barrier_last_time_opened = current_time; + if (!car_spot_controller.is_empty() && barrier.is_closed()){ + barrier.open(); + car_spot_controller.decrement_occupied_spots(); + } + } + if (current_time - sensor_last_time_readed >= 1000){ if (dist_sensor.is_in_range()){ - sensor_last_time_activated = current_time; + barrier_last_time_opened = current_time; if(barrier.is_closed()){ if (!car_spot_controller.is_full()){ barrier.open(); @@ -55,7 +71,7 @@ void loop() { } } } 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 - barrier_last_time_opened >= barrier.open_time_seconds * 1000 && !button.is_pressed()){ barrier.close(); } }