Update stable version 24/05/2025 #2
@ -4,6 +4,7 @@
|
|||||||
enum LCDScreenState {
|
enum LCDScreenState {
|
||||||
DISPLAY_DEFAULT_MESSAGE,
|
DISPLAY_DEFAULT_MESSAGE,
|
||||||
DISPLAY_TEMPERATURE,
|
DISPLAY_TEMPERATURE,
|
||||||
|
DISPLAY_PARKING_SPOTS_FULL,
|
||||||
DISPLAY_PARKING_SPOTS
|
DISPLAY_PARKING_SPOTS
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -46,4 +47,18 @@ class LCDScreen {
|
|||||||
lcd.print(this->default_message);
|
lcd.print(this->default_message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void display_message_full(){
|
||||||
|
this->state = DISPLAY_PARKING_SPOTS_FULL;
|
||||||
|
lcd.setCursor(0, 0);
|
||||||
|
this->clear();
|
||||||
|
lcd.print("Parking Lot is FULL.\nPlease come back later.\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void display_message(int slots){
|
||||||
|
this->state = DISPLAY_PARKING_SPOTS;
|
||||||
|
lcd.setCursor(0, 0);
|
||||||
|
this->clear();
|
||||||
|
lcd.print("Available slots: ");
|
||||||
|
lcd.print(slots); lcd.print('\n');
|
||||||
|
}
|
||||||
};
|
};
|
||||||
@ -6,11 +6,14 @@
|
|||||||
#include "DistSensor.cpp";
|
#include "DistSensor.cpp";
|
||||||
#include "LCDScreen.cpp";
|
#include "LCDScreen.cpp";
|
||||||
|
|
||||||
|
#define PARK_SLOTS = 8;
|
||||||
#define ULTRASONIC_SENSOR_PIN_TRIG 11
|
#define ULTRASONIC_SENSOR_PIN_TRIG 11
|
||||||
#define ULTRASONIC_SENSOR_PIN_ECHO 12
|
#define ULTRASONIC_SENSOR_PIN_ECHO 12
|
||||||
#define SERVO_PIN 10
|
#define SERVO_PIN 10
|
||||||
#define SERVO_PIN 10
|
#define SERVO_PIN 10
|
||||||
#define TEMP_SENSOR_PIN 9
|
#define TEMP_SENSOR_PIN 9
|
||||||
|
#define BUTTON_PIN = 8;
|
||||||
|
#define BUZZER_PIN = 3;
|
||||||
|
|
||||||
OneWire oneWire(TEMP_SENSOR_PIN);
|
OneWire oneWire(TEMP_SENSOR_PIN);
|
||||||
DallasTemperature sensors(&oneWire);
|
DallasTemperature sensors(&oneWire);
|
||||||
@ -20,6 +23,7 @@ Barrier barrier = Barrier(SERVO_PIN, 3);
|
|||||||
LCDScreen screen = LCDScreen();
|
LCDScreen screen = LCDScreen();
|
||||||
|
|
||||||
unsigned long current_time, sensor_last_time_activated, temperature_last_time_measured;
|
unsigned long current_time, sensor_last_time_activated, temperature_last_time_measured;
|
||||||
|
int OCCUPIED_SLOTS = 0, Button_State = 0, Last_Button_State = 0;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
@ -27,31 +31,57 @@ void setup() {
|
|||||||
barrier.configure_pins();
|
barrier.configure_pins();
|
||||||
sensors.begin();
|
sensors.begin();
|
||||||
screen.init();
|
screen.init();
|
||||||
|
pinMode(BUTTON_PIN, INPUT);
|
||||||
|
pinMode(BUZZER_PIN, OUTPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
|
||||||
current_time = millis();
|
current_time = millis();
|
||||||
|
Button_State = digitalRead(BUTTON_PIN);
|
||||||
|
|
||||||
|
// Carro entra:
|
||||||
if (dist_sensor.is_in_range()){
|
if (dist_sensor.is_in_range()){
|
||||||
sensor_last_time_activated = current_time;
|
sensor_last_time_activated_IN = current_time;
|
||||||
if(barrier.is_closed()){
|
if(barrier.is_closed()){
|
||||||
barrier.open();
|
barrier.open();
|
||||||
}
|
}
|
||||||
} 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_IN >= barrier.open_time_seconds * 1000){
|
||||||
|
barrier.close();
|
||||||
|
OCCUPIED_SLOTS++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Carro sai:
|
||||||
|
if (Button_State != Last_Button_State){
|
||||||
|
sensor_last_time_activated_OUT = current_time;
|
||||||
|
if(barrier.is_closed()){
|
||||||
|
barrier.open();
|
||||||
|
if (Button_State == HIGH) {
|
||||||
|
OCCUPIED_SLOTS--;
|
||||||
|
screen.display_message(OCCUPIED_SLOTS);
|
||||||
|
if (OCCUPIED_SLOTS == PARK_SLOTS) {
|
||||||
|
screen.display_message_full();
|
||||||
|
tone(BUZZER_PIN, 1000); delayMicroseconds(500);
|
||||||
|
noTone(BUZZER_PIN);
|
||||||
|
tone(BUZZER_PIN, 1000); delayMicroseconds(500);
|
||||||
|
noTone(BUZZER_PIN);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (!dist_sensor.is_in_range() && barrier.is_open()){
|
||||||
|
if (current_time - sensor_last_time_activated_OUT >= barrier.open_time_seconds * 1000){
|
||||||
barrier.close();
|
barrier.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Last_Button_State = Button_State;
|
||||||
|
|
||||||
|
// Temperatura:
|
||||||
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;
|
||||||
sensors.requestTemperatures();
|
sensors.requestTemperatures();
|
||||||
float tempC = sensors.getTempCByIndex(0);
|
float tempC = sensors.getTempCByIndex(0);
|
||||||
screen.display_temperature(tempC);
|
screen.display_temperature(tempC);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user