Merge branch 'dev' of https://git.rafajr.dev/rafa/SE-TP2 into dev
This commit is contained in:
commit
99ba0b5afc
@ -24,14 +24,18 @@ class Barrier {
|
||||
}
|
||||
|
||||
void open(){
|
||||
if (this->state != OPEN){
|
||||
this->state = OPEN;
|
||||
this->servo.write(0);
|
||||
}
|
||||
}
|
||||
|
||||
void close(){
|
||||
if(this->state != CLOSED){
|
||||
this->state = CLOSED;
|
||||
this->servo.write(90);
|
||||
}
|
||||
}
|
||||
|
||||
bool is_open() const {
|
||||
return this->state == OPEN;
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -33,17 +33,22 @@ class LCDScreen {
|
||||
}
|
||||
|
||||
void display_temperature(float temp){
|
||||
this->state = DISPLAY_TEMPERATURE;
|
||||
lcd.setCursor(0, 0);
|
||||
if (this->state != DISPLAY_TEMPERATURE){
|
||||
this->clear();
|
||||
lcd.print(temp);
|
||||
lcd.print(" C");
|
||||
this->state = DISPLAY_TEMPERATURE;
|
||||
}
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.print("Temp: ");
|
||||
lcd.print(temp,1);
|
||||
lcd.print(" C ");
|
||||
}
|
||||
|
||||
void display_default_message(){
|
||||
this->state = DISPLAY_DEFAULT_MESSAGE;
|
||||
lcd.setCursor(0, 0);
|
||||
if (this->state != DISPLAY_DEFAULT_MESSAGE){
|
||||
this->clear();
|
||||
this->state = DISPLAY_DEFAULT_MESSAGE;
|
||||
}
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.print(this->default_message);
|
||||
}
|
||||
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user