From 3b04428c7f8765e5b3630f5e5d8d150f084cf8a3 Mon Sep 17 00:00:00 2001 From: bray Date: Wed, 20 May 2020 11:44:55 +0200 Subject: [PATCH] Electrovanne terminee et fonctionelle --- .../AnalogSensors/AnalogSensorManometre.cpp | 2 +- .../DigitalActuatorElectrovanne.cpp | 25 ++----------------- .../DigitalActuatorRadiator.cpp | 24 +----------------- board.cpp | 8 +++--- core_simulation.h | 3 +-- .../DigitalActuatorElectrovanne.h | 18 +++---------- .../DigitalActuatorRadiator.h | 14 +---------- sketch_ino.cpp | 25 +++++++++++++------ 8 files changed, 31 insertions(+), 88 deletions(-) diff --git a/OtherDevices/AnalogDevices/AnalogSensors/AnalogSensorManometre.cpp b/OtherDevices/AnalogDevices/AnalogSensors/AnalogSensorManometre.cpp index 502968e..3702abe 100644 --- a/OtherDevices/AnalogDevices/AnalogSensors/AnalogSensorManometre.cpp +++ b/OtherDevices/AnalogDevices/AnalogSensors/AnalogSensorManometre.cpp @@ -7,7 +7,7 @@ int AnalogSensorManometre::alea = -1; AnalogSensorManometre::AnalogSensorManometre(int val, int temps):AnalogDevice(val,temps){ - AnalogSensorManometre::alea=-1; + AnalogSensorManometre::alea = -1; } void AnalogSensorManometre::run(){ diff --git a/OtherDevices/DigitalDevices/DigitalActuators/DigitalActuatorElectrovanne.cpp b/OtherDevices/DigitalDevices/DigitalActuators/DigitalActuatorElectrovanne.cpp index b5c3b8b..a3e2ed5 100644 --- a/OtherDevices/DigitalDevices/DigitalActuators/DigitalActuatorElectrovanne.cpp +++ b/OtherDevices/DigitalDevices/DigitalActuators/DigitalActuatorElectrovanne.cpp @@ -5,19 +5,14 @@ #include "../../../include/DigitalDevices/DigitalActuators/DigitalActuatorElectrovanne.h" #include "../../../include/AnalogDevices/AnalogSensors/AnalogSensorManometre.h" -DigitalActuatorElectrovanne::DigitalActuatorElectrovanne(int temps, float thresholdHigh, float thresholdLow) : DigitalActuator(temps), - thresholdHigh(thresholdHigh), thresholdLow(thresholdLow) {} - -void DigitalActuatorElectrovanne::activate() { - DigitalDevice::state = HIGH; -} +DigitalActuatorElectrovanne::DigitalActuatorElectrovanne(int temps) : DigitalActuator(temps){} void DigitalActuatorElectrovanne::run() { int previousState = LOW; while (1){ state = *ptrmem; if ((state != previousState)&&(state == HIGH)){ - AnalogSensorManometre::setAlea(1); + AnalogSensorManometre::setAlea(5); previousState = HIGH; } else if((state != previousState)&&(state == LOW)) { AnalogSensorManometre::setAlea(-1); @@ -25,19 +20,3 @@ void DigitalActuatorElectrovanne::run() { } } } - -float DigitalActuatorElectrovanne::getThresholdLow() const { - return thresholdLow; -} - -void DigitalActuatorElectrovanne::setThresholdLow(float thresholdLow) { - DigitalActuatorElectrovanne::thresholdLow = thresholdLow; -} - -float DigitalActuatorElectrovanne::getThresholdHigh() const { - return thresholdHigh; -} - -void DigitalActuatorElectrovanne::setThresholdHigh(float threshold) { - DigitalActuatorElectrovanne::thresholdHigh = threshold; -} diff --git a/OtherDevices/DigitalDevices/DigitalActuators/DigitalActuatorRadiator.cpp b/OtherDevices/DigitalDevices/DigitalActuators/DigitalActuatorRadiator.cpp index b452e88..c806ed9 100644 --- a/OtherDevices/DigitalDevices/DigitalActuators/DigitalActuatorRadiator.cpp +++ b/OtherDevices/DigitalDevices/DigitalActuators/DigitalActuatorRadiator.cpp @@ -4,13 +4,7 @@ #include "../../../include/DigitalDevices/DigitalActuators/DigitalActuatorRadiator.h" -DigitalActuatorRadiator::DigitalActuatorRadiator(int temps, float thresholdHigh, float thresholdLow) : DigitalActuator(temps), -thresholdHigh(thresholdHigh), thresholdLow(thresholdLow) {} - -void DigitalActuatorRadiator::activate() { - DigitalDevice::state = HIGH; -} - +DigitalActuatorRadiator::DigitalActuatorRadiator(int temps) : DigitalActuator(temps){} void DigitalActuatorRadiator::run() { int previousState = LOW; while (1){ @@ -24,19 +18,3 @@ void DigitalActuatorRadiator::run() { } } } - -float DigitalActuatorRadiator::getThresholdLow() const { - return thresholdLow; -} - -void DigitalActuatorRadiator::setThresholdLow(float thresholdLow) { - DigitalActuatorRadiator::thresholdLow = thresholdLow; -} - -float DigitalActuatorRadiator::getThresholdHigh() const { - return thresholdHigh; -} - -void DigitalActuatorRadiator::setThresholdHigh(float threshold) { - DigitalActuatorRadiator::thresholdHigh = threshold; -} diff --git a/board.cpp b/board.cpp index cb7b693..7512bd2 100644 --- a/board.cpp +++ b/board.cpp @@ -6,6 +6,7 @@ #include "include/DigitalDevices/DigitalSensors/ExternalDigitalSensorButton.h" #include "include/AnalogDevices/AnalogSensors/AnalogSensorManometre.h" #include "include/DigitalDevices/DigitalActuators/DigitalActuatorRadiator.h" +#include "include/DigitalDevices/DigitalActuators/DigitalActuatorElectrovanne.h" int main(){ // creation d'une board @@ -17,14 +18,15 @@ int main(){ I2CActuatorScreen screen; AnalogSensorLuminosity luminosite(DELAY); ExternalDigitalSensorButton button(DELAY); - AnalogSensorManometre manometre(4,DELAY); - DigitalActuatorRadiator radiator(DELAY, THRESHOLDHIGH, THRESHOLDLOW); + AnalogSensorManometre manometre(PRESSURE,DELAY); + DigitalActuatorRadiator radiator(DELAY); + DigitalActuatorElectrovanne electrovanne(DELAY); // branchement des capteurs actionneurs esp8266.pin(1,temperature); //esp8266.pin(0,led1); - esp8266.pin(2, luminosite); + esp8266.pin(2, electrovanne); esp8266.i2c(1,screen); esp8266.pin(4, button); esp8266.pin(5, manometre); diff --git a/core_simulation.h b/core_simulation.h index c610f79..16d5afb 100644 --- a/core_simulation.h +++ b/core_simulation.h @@ -8,13 +8,12 @@ #define DELAY 3 #define TEMP 17 +#define PRESSURE 2995 #define HIGH 1 #define LOW 0 #define MAX_I2C_DEVICES 4 #define I2C_BUFFER_SIZE 1024 #define MAX_IO_PIN 6 -#define THRESHOLDHIGH 25 -#define THRESHOLDLOW 20 using namespace std; diff --git a/include/DigitalDevices/DigitalActuators/DigitalActuatorElectrovanne.h b/include/DigitalDevices/DigitalActuators/DigitalActuatorElectrovanne.h index 6d79ce5..1986281 100644 --- a/include/DigitalDevices/DigitalActuators/DigitalActuatorElectrovanne.h +++ b/include/DigitalDevices/DigitalActuators/DigitalActuatorElectrovanne.h @@ -9,21 +9,9 @@ #include "../DigitalDevice.h" class DigitalActuatorElectrovanne : public DigitalActuator{ - private: - float thresholdHigh, thresholdLow; - - public: - DigitalActuatorElectrovanne(int temps, float threshold, float thresholdLow); - - float getThresholdHigh() const; - void setThresholdHigh(float threshold); - - float getThresholdLow() const; - - void setThresholdLow(float thresholdLow); - - void activate(); - void run(); +public: + DigitalActuatorElectrovanne(int temps); + void run(); }; diff --git a/include/DigitalDevices/DigitalActuators/DigitalActuatorRadiator.h b/include/DigitalDevices/DigitalActuators/DigitalActuatorRadiator.h index 79c3fa3..e72e055 100644 --- a/include/DigitalDevices/DigitalActuators/DigitalActuatorRadiator.h +++ b/include/DigitalDevices/DigitalActuators/DigitalActuatorRadiator.h @@ -10,20 +10,8 @@ #include "../../../include/AnalogDevices/AnalogSensors/AnalogSensorTemperature.h" class DigitalActuatorRadiator : public DigitalActuator { -private: - float thresholdHigh, thresholdLow; - public: - DigitalActuatorRadiator(int temps, float threshold, float thresholdLow); - - float getThresholdHigh() const; - void setThresholdHigh(float threshold); - - float getThresholdLow() const; - - void setThresholdLow(float thresholdLow); - - void activate(); + DigitalActuatorRadiator(int temps); void run(); }; diff --git a/sketch_ino.cpp b/sketch_ino.cpp index 3130dcc..c504190 100644 --- a/sketch_ino.cpp +++ b/sketch_ino.cpp @@ -17,15 +17,11 @@ void Board::setup(){ Serial.begin(9600); // on fixe les pin en entree et en sorite en fonction des capteurs/actionneurs mis sur la carte pinMode(1, INPUT); - pinMode(0, OUTPUT); - pinMode(2, INPUT); pinMode(4, INPUT); pinMode(5, INPUT); - - - - + pinMode(0, OUTPUT); + pinMode(2, OUTPUT); digitalWrite(0,LOW); //pinMode(6, OUTPUT); @@ -57,11 +53,24 @@ void Board::loop(){ // lecture sur la pin 2 : capteur de temperature - val = analogRead(2); - sprintf(buf, "luminosite %d", val); + pressure.setValue(analogRead(5)); + sprintf(buf, "pressure %f", pressure.getValue()); Serial.println(buf); + + if ((pressure.is2Low()) && (terrarium.getTapState() == LOW)) { + digitalWrite(2, HIGH); + terrarium.setTapState(HIGH); + } + else if ((pressure.is2High() ) && (terrarium.getTapState() == HIGH)) { + digitalWrite(2, LOW); + terrarium.setTapState(LOW); + } + // } + + + // if(cpt%5==0){ // tous les 5 fois on affiche sur l ecran la temperature sprintf(buf,"%d",val1);