Update stable version 24/05/2025 #2

Merged
rafa merged 29 commits from dev into main 2025-05-24 20:00:44 +02:00
4 changed files with 37 additions and 27 deletions
Showing only changes of commit 99ba0b5afc - Show all commits

View File

@ -24,13 +24,17 @@ class Barrier {
}
void open(){
this->state = OPEN;
this->servo.write(0);
if (this->state != OPEN){
this->state = OPEN;
this->servo.write(0);
}
}
void close(){
this->state = CLOSED;
this->servo.write(90);
if(this->state != CLOSED){
this->state = CLOSED;
this->servo.write(90);
}
}
bool is_open() const {

View File

@ -3,34 +3,34 @@
class DistSensor {
private:
int trigPin;
int echoPin;
int trig_pin;
int echo_pin;
const int ULTRASONIC_CM_FACTOR = 58;
void make_measurement(){
digitalWrite(this->trigPin, HIGH);
digitalWrite(this->trig_pin, HIGH);
delayMicroseconds(10);
digitalWrite(this->trigPin, LOW);
digitalWrite(this->trig_pin, LOW);
}
public:
int duration;
float default_distance;
DistSensor(int trigPin, int echoPin, float default_distance){
this->trigPin = trigPin;
this->echoPin = echoPin;
DistSensor(int trig_pin, int echo_pin, float default_distance){
this->trig_pin = trig_pin;
this->echo_pin = echo_pin;
this->default_distance = default_distance;
}
void configure_pins(){
pinMode(this->trigPin, OUTPUT);
pinMode(this->echoPin, INPUT);
pinMode(this->trig_pin, OUTPUT);
pinMode(this->echo_pin, INPUT);
}
int get_duration(){
this->make_measurement();
this->duration = pulseIn(this->echoPin, HIGH);
this->duration = pulseIn(this->echo_pin, HIGH);
return this->duration;
}

View File

@ -33,17 +33,22 @@ class LCDScreen {
}
void display_temperature(float temp){
this->state = DISPLAY_TEMPERATURE;
if (this->state != DISPLAY_TEMPERATURE){
this->clear();
this->state = DISPLAY_TEMPERATURE;
}
lcd.setCursor(0, 0);
this->clear();
lcd.print(temp);
lcd.print(" C");
lcd.print("Temp: ");
lcd.print(temp,1);
lcd.print(" C ");
}
void display_default_message(){
this->state = DISPLAY_DEFAULT_MESSAGE;
if (this->state != DISPLAY_DEFAULT_MESSAGE){
this->clear();
this->state = DISPLAY_DEFAULT_MESSAGE;
}
lcd.setCursor(0, 0);
this->clear();
lcd.print(this->default_message);
}

View File

@ -10,26 +10,26 @@
#define ULTRASONIC_SENSOR_PIN_TRIG 11
#define ULTRASONIC_SENSOR_PIN_ECHO 12
#define SERVO_PIN 10
#define SERVO_PIN 10
#define TEMP_SENSOR_PIN 9
#define BUTTON_PIN = 8;
#define BUZZER_PIN = 3;
OneWire oneWire(TEMP_SENSOR_PIN);
DallasTemperature sensors(&oneWire);
DallasTemperature temperature_sensors(&oneWire);
DistSensor dist_sensor = DistSensor(ULTRASONIC_SENSOR_PIN_TRIG, ULTRASONIC_SENSOR_PIN_ECHO, 25.0);
Barrier barrier = Barrier(SERVO_PIN, 3);
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() {
Serial.begin(9600);
dist_sensor.configure_pins();
barrier.configure_pins();
sensors.begin();
temperature_sensors.begin();
screen.init();
pinMode(BUTTON_PIN, INPUT);
pinMode(BUZZER_PIN, OUTPUT);
@ -80,8 +80,9 @@ void loop() {
// Temperatura:
if (current_time - temperature_last_time_measured >= 1000){
temperature_last_time_measured = current_time;
sensors.requestTemperatures();
float tempC = sensors.getTempCByIndex(0);
screen.display_temperature(tempC);
temperature_sensors.requestTemperatures();
temperature_in_c = temperature_sensors.getTempCByIndex(0);
}
screen.display_temperature(temperature_in_c);
}