Compare commits
2 Commits
87a69782e5
...
99ba0b5afc
| Author | SHA1 | Date | |
|---|---|---|---|
| 99ba0b5afc | |||
| 5fadd48222 |
@ -4,6 +4,7 @@
|
||||
enum LCDScreenState {
|
||||
DISPLAY_DEFAULT_MESSAGE,
|
||||
DISPLAY_TEMPERATURE,
|
||||
DISPLAY_PARKING_SPOTS_FULL,
|
||||
DISPLAY_PARKING_SPOTS
|
||||
};
|
||||
|
||||
@ -51,4 +52,18 @@ class LCDScreen {
|
||||
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,10 +6,13 @@
|
||||
#include "DistSensor.cpp";
|
||||
#include "LCDScreen.cpp";
|
||||
|
||||
#define PARK_SLOTS = 8;
|
||||
#define ULTRASONIC_SENSOR_PIN_TRIG 11
|
||||
#define ULTRASONIC_SENSOR_PIN_ECHO 12
|
||||
#define SERVO_PIN 10
|
||||
#define TEMP_SENSOR_PIN 9
|
||||
#define BUTTON_PIN = 8;
|
||||
#define BUZZER_PIN = 3;
|
||||
|
||||
OneWire oneWire(TEMP_SENSOR_PIN);
|
||||
DallasTemperature temperature_sensors(&oneWire);
|
||||
@ -19,7 +22,7 @@ Barrier barrier = Barrier(SERVO_PIN, 4);
|
||||
LCDScreen screen = LCDScreen();
|
||||
|
||||
unsigned long current_time, sensor_last_time_activated, temperature_last_time_measured;
|
||||
|
||||
int OCCUPIED_SLOTS = 0, Button_State = 0, Last_Button_State = 0;
|
||||
float temperature_in_c = 0;
|
||||
|
||||
void setup() {
|
||||
@ -28,24 +31,53 @@ void setup() {
|
||||
barrier.configure_pins();
|
||||
temperature_sensors.begin();
|
||||
screen.init();
|
||||
|
||||
pinMode(BUTTON_PIN, INPUT);
|
||||
pinMode(BUZZER_PIN, OUTPUT);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
current_time = millis();
|
||||
Button_State = digitalRead(BUTTON_PIN);
|
||||
|
||||
// Carro entra:
|
||||
if (dist_sensor.is_in_range()){
|
||||
sensor_last_time_activated = current_time;
|
||||
sensor_last_time_activated_IN = current_time;
|
||||
if(barrier.is_closed()){
|
||||
barrier.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();
|
||||
}
|
||||
}
|
||||
Last_Button_State = Button_State;
|
||||
|
||||
// Temperatura:
|
||||
if (current_time - temperature_last_time_measured >= 1000){
|
||||
temperature_last_time_measured = current_time;
|
||||
temperature_sensors.requestTemperatures();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user