Compare commits
No commits in common. "87a69782e52eca1bf382367a96301b9c4cc016ef" and "1e2bffaedd5525f47a67950e7da60f9aeec3fb01" have entirely different histories.
87a69782e5
...
1e2bffaedd
@ -24,18 +24,14 @@ class Barrier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void open(){
|
void open(){
|
||||||
if (this->state != OPEN){
|
|
||||||
this->state = OPEN;
|
this->state = OPEN;
|
||||||
this->servo.write(0);
|
this->servo.write(0);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void close(){
|
void close(){
|
||||||
if(this->state != CLOSED){
|
|
||||||
this->state = CLOSED;
|
this->state = CLOSED;
|
||||||
this->servo.write(90);
|
this->servo.write(90);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
bool is_open() const {
|
bool is_open() const {
|
||||||
return this->state == OPEN;
|
return this->state == OPEN;
|
||||||
|
|||||||
@ -3,34 +3,34 @@
|
|||||||
class DistSensor {
|
class DistSensor {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int trig_pin;
|
int trigPin;
|
||||||
int echo_pin;
|
int echoPin;
|
||||||
const int ULTRASONIC_CM_FACTOR = 58;
|
const int ULTRASONIC_CM_FACTOR = 58;
|
||||||
|
|
||||||
void make_measurement(){
|
void make_measurement(){
|
||||||
digitalWrite(this->trig_pin, HIGH);
|
digitalWrite(this->trigPin, HIGH);
|
||||||
delayMicroseconds(10);
|
delayMicroseconds(10);
|
||||||
digitalWrite(this->trig_pin, LOW);
|
digitalWrite(this->trigPin, LOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int duration;
|
int duration;
|
||||||
float default_distance;
|
float default_distance;
|
||||||
|
|
||||||
DistSensor(int trig_pin, int echo_pin, float default_distance){
|
DistSensor(int trigPin, int echoPin, float default_distance){
|
||||||
this->trig_pin = trig_pin;
|
this->trigPin = trigPin;
|
||||||
this->echo_pin = echo_pin;
|
this->echoPin = echoPin;
|
||||||
this->default_distance = default_distance;
|
this->default_distance = default_distance;
|
||||||
}
|
}
|
||||||
|
|
||||||
void configure_pins(){
|
void configure_pins(){
|
||||||
pinMode(this->trig_pin, OUTPUT);
|
pinMode(this->trigPin, OUTPUT);
|
||||||
pinMode(this->echo_pin, INPUT);
|
pinMode(this->echoPin, INPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
int get_duration(){
|
int get_duration(){
|
||||||
this->make_measurement();
|
this->make_measurement();
|
||||||
this->duration = pulseIn(this->echo_pin, HIGH);
|
this->duration = pulseIn(this->echoPin, HIGH);
|
||||||
return this->duration;
|
return this->duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -32,22 +32,17 @@ class LCDScreen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void display_temperature(float temp){
|
void display_temperature(float temp){
|
||||||
if (this->state != DISPLAY_TEMPERATURE){
|
|
||||||
this->clear();
|
|
||||||
this->state = DISPLAY_TEMPERATURE;
|
this->state = DISPLAY_TEMPERATURE;
|
||||||
}
|
|
||||||
lcd.setCursor(0, 0);
|
lcd.setCursor(0, 0);
|
||||||
lcd.print("Temp: ");
|
this->clear();
|
||||||
lcd.print(temp,1);
|
lcd.print(temp);
|
||||||
lcd.print(" C ");
|
lcd.print(" C");
|
||||||
}
|
}
|
||||||
|
|
||||||
void display_default_message(){
|
void display_default_message(){
|
||||||
if (this->state != DISPLAY_DEFAULT_MESSAGE){
|
|
||||||
this->clear();
|
|
||||||
this->state = DISPLAY_DEFAULT_MESSAGE;
|
this->state = DISPLAY_DEFAULT_MESSAGE;
|
||||||
}
|
|
||||||
lcd.setCursor(0, 0);
|
lcd.setCursor(0, 0);
|
||||||
|
this->clear();
|
||||||
lcd.print(this->default_message);
|
lcd.print(this->default_message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -9,24 +9,23 @@
|
|||||||
#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 TEMP_SENSOR_PIN 9
|
#define TEMP_SENSOR_PIN 9
|
||||||
|
|
||||||
OneWire oneWire(TEMP_SENSOR_PIN);
|
OneWire oneWire(TEMP_SENSOR_PIN);
|
||||||
DallasTemperature temperature_sensors(&oneWire);
|
DallasTemperature sensors(&oneWire);
|
||||||
|
|
||||||
DistSensor dist_sensor = DistSensor(ULTRASONIC_SENSOR_PIN_TRIG, ULTRASONIC_SENSOR_PIN_ECHO, 25.0);
|
DistSensor dist_sensor = DistSensor(ULTRASONIC_SENSOR_PIN_TRIG, ULTRASONIC_SENSOR_PIN_ECHO, 25.0);
|
||||||
Barrier barrier = Barrier(SERVO_PIN, 4);
|
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;
|
||||||
|
|
||||||
float temperature_in_c = 0;
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
dist_sensor.configure_pins();
|
dist_sensor.configure_pins();
|
||||||
barrier.configure_pins();
|
barrier.configure_pins();
|
||||||
temperature_sensors.begin();
|
sensors.begin();
|
||||||
screen.init();
|
screen.init();
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -48,9 +47,11 @@ void loop() {
|
|||||||
|
|
||||||
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;
|
||||||
temperature_sensors.requestTemperatures();
|
sensors.requestTemperatures();
|
||||||
temperature_in_c = temperature_sensors.getTempCByIndex(0);
|
float tempC = sensors.getTempCByIndex(0);
|
||||||
|
screen.display_temperature(tempC);
|
||||||
}
|
}
|
||||||
|
|
||||||
screen.display_temperature(temperature_in_c);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user