Update stable version 24/05/2025 #2
@ -21,10 +21,10 @@ 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, 2);
|
Barrier barrier = Barrier(SERVO_PIN, 2);
|
||||||
LCDScreen screen = LCDScreen();
|
LCDScreen screen = LCDScreen();
|
||||||
CarSpotCOntroller car_spot_controller = CarSpotCOntroller(2);
|
CarSpotController car_spot_controller = CarSpotController(2);
|
||||||
JoySitkController joystick = JoySitkController(JOYSTICK_X_PIN, JOYSTICK_Y_PIN);
|
JoystickController joystick = JoystickController(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_readed, sensor_last_time_activated, temperature_last_time_measured, joystick_last_time_activated, joystick_last_time_readed, screen_last_time_updated;
|
||||||
|
|
||||||
float temperature_in_c = 0;
|
float temperature_in_c = 0;
|
||||||
|
|
||||||
@ -37,10 +37,12 @@ void setup() {
|
|||||||
screen.init();
|
screen.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
|
||||||
current_time = millis();
|
current_time = millis();
|
||||||
|
|
||||||
|
if (current_time - sensor_last_time_readed >= 1000){
|
||||||
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()){
|
||||||
@ -56,31 +58,29 @@ void loop() {
|
|||||||
barrier.close();
|
barrier.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (current_time - temperature_last_time_measured >= 1000){
|
if (current_time - temperature_last_time_measured >= 1000){
|
||||||
temperature_last_time_measured = current_time;
|
temperature_last_time_measured = current_time;
|
||||||
|
temperature_sensors.setWaitForConversion(false);
|
||||||
temperature_sensors.requestTemperatures();
|
temperature_sensors.requestTemperatures();
|
||||||
temperature_in_c = temperature_sensors.getTempCByIndex(0);
|
temperature_in_c = temperature_sensors.getTempCByIndex(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
joystick.read();
|
if (joystick.is_moving_right() && current_time - joystick_last_time_activated >= 450){
|
||||||
|
|
||||||
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 >= 450){
|
||||||
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());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (current_time - screen_last_time_updated >= 500){
|
||||||
|
screen_last_time_updated = current_time;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user