From 3b0cdae87141a7a9b6cd00194c1c00c338299778 Mon Sep 17 00:00:00 2001 From: bray Date: Tue, 12 May 2020 12:33:35 +0200 Subject: [PATCH] boutton fait mais led allume sans raison --- board.cpp | 2 ++ mydevices.cpp | 18 ++++++++++++++++++ mydevices.h | 11 ++++++++++- sketch_ino.cpp | 4 +++- 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/board.cpp b/board.cpp index b021a2f..74fa013 100644 --- a/board.cpp +++ b/board.cpp @@ -11,12 +11,14 @@ int main(){ IntelligentDigitalActuatorLED led1(DELAY); I2CActuatorScreen screen; AnalogSensorLuminosity luminosite(DELAY); + ExternalDigitalSensorButton button(DELAY); // branchement des capteurs actionneurs esp8266.pin(1,temperature); esp8266.pin(0,led1); esp8266.pin(2, luminosite); esp8266.i2c(1,screen); + esp8266.pin(4, button); // allumage de la carte esp8266.run(); diff --git a/mydevices.cpp b/mydevices.cpp index 0662bf1..e00f26e 100644 --- a/mydevices.cpp +++ b/mydevices.cpp @@ -96,5 +96,23 @@ void I2CActuatorScreen::run(){ } +int ExternalDigitalSensorButton::getState(){ + if (ifstream("on.txt")){ + state = 1; + } else { + state = 0; + } + return state; +} +ExternalDigitalSensorButton::ExternalDigitalSensorButton(int temps) { + state = 0; + this->temps = temps; +} +void ExternalDigitalSensorButton::run() { + while (1) { + *ptrmem = this->getState(); + sleep(temps); + } +} diff --git a/mydevices.h b/mydevices.h index 6fba4fe..1cef82d 100644 --- a/mydevices.h +++ b/mydevices.h @@ -5,6 +5,7 @@ #include #include #include +#include #include "core_simulation.h" static int luminosite_environnement = 200; @@ -93,7 +94,15 @@ public: virtual void run(); }; - +class ExternalDigitalSensorButton : public Device{ +private: + int state; + int temps; +public: + ExternalDigitalSensorButton(int temps); + virtual void run(); + int getState(); +}; //class ExternalDigitalSensorButton: public Device diff --git a/sketch_ino.cpp b/sketch_ino.cpp index b165e28..77d52df 100644 --- a/sketch_ino.cpp +++ b/sketch_ino.cpp @@ -9,6 +9,7 @@ void Board::setup(){ pinMode(1,INPUT); pinMode(0,OUTPUT); pinMode(2,INPUT); + pinMode(4, INPUT); } // la boucle de controle arduino @@ -29,6 +30,7 @@ void Board::loop(){ val=analogRead(2); sprintf(buf,"luminosite %d",val); Serial.println(buf); + if(cpt%5==0){ // tous les 5 fois on affiche sur l ecran la temperature @@ -41,7 +43,7 @@ void Board::loop(){ sleep(1); } // on eteint et on allume la LED - if(bascule) + if(analogRead(4)) digitalWrite(0,HIGH); else digitalWrite(0,LOW);