boutton fait mais led allume sans raison

This commit is contained in:
Cameron Bray 2020-05-12 12:33:35 +02:00
parent 5922e4e7b5
commit 3b0cdae871
4 changed files with 33 additions and 2 deletions

View file

@ -11,12 +11,14 @@ int main(){
IntelligentDigitalActuatorLED led1(DELAY); IntelligentDigitalActuatorLED led1(DELAY);
I2CActuatorScreen screen; I2CActuatorScreen screen;
AnalogSensorLuminosity luminosite(DELAY); AnalogSensorLuminosity luminosite(DELAY);
ExternalDigitalSensorButton button(DELAY);
// branchement des capteurs actionneurs // branchement des capteurs actionneurs
esp8266.pin(1,temperature); esp8266.pin(1,temperature);
esp8266.pin(0,led1); esp8266.pin(0,led1);
esp8266.pin(2, luminosite); esp8266.pin(2, luminosite);
esp8266.i2c(1,screen); esp8266.i2c(1,screen);
esp8266.pin(4, button);
// allumage de la carte // allumage de la carte
esp8266.run(); esp8266.run();

View file

@ -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);
}
}

View file

@ -5,6 +5,7 @@
#include <thread> #include <thread>
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
#include <fstream>
#include "core_simulation.h" #include "core_simulation.h"
static int luminosite_environnement = 200; static int luminosite_environnement = 200;
@ -93,7 +94,15 @@ public:
virtual void run(); 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 //class ExternalDigitalSensorButton: public Device

View file

@ -9,6 +9,7 @@ void Board::setup(){
pinMode(1,INPUT); pinMode(1,INPUT);
pinMode(0,OUTPUT); pinMode(0,OUTPUT);
pinMode(2,INPUT); pinMode(2,INPUT);
pinMode(4, INPUT);
} }
// la boucle de controle arduino // la boucle de controle arduino
@ -30,6 +31,7 @@ void Board::loop(){
sprintf(buf,"luminosite %d",val); sprintf(buf,"luminosite %d",val);
Serial.println(buf); Serial.println(buf);
if(cpt%5==0){ if(cpt%5==0){
// tous les 5 fois on affiche sur l ecran la temperature // tous les 5 fois on affiche sur l ecran la temperature
sprintf(buf,"%d",val1); sprintf(buf,"%d",val1);
@ -41,7 +43,7 @@ void Board::loop(){
sleep(1); sleep(1);
} }
// on eteint et on allume la LED // on eteint et on allume la LED
if(bascule) if(analogRead(4))
digitalWrite(0,HIGH); digitalWrite(0,HIGH);
else else
digitalWrite(0,LOW); digitalWrite(0,LOW);