diff --git a/code/Barrier.cpp b/code/Barrier.cpp index 4be3e2a..bf5ce20 100644 --- a/code/Barrier.cpp +++ b/code/Barrier.cpp @@ -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 { diff --git a/code/LCDScreen.cpp b/code/LCDScreen.cpp index ecdc9bb..e9e2f64 100644 --- a/code/LCDScreen.cpp +++ b/code/LCDScreen.cpp @@ -32,17 +32,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); } diff --git a/code/code.ino b/code/code.ino index 76306f8..04a6423 100644 --- a/code/code.ino +++ b/code/code.ino @@ -9,18 +9,19 @@ #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 OneWire oneWire(TEMP_SENSOR_PIN); DallasTemperature 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; +float tempC = 0; + void setup() { Serial.begin(9600); dist_sensor.configure_pins(); @@ -48,10 +49,8 @@ void loop() { 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); + tempC = sensors.getTempCByIndex(0); } - - + screen.display_temperature(tempC); }