Plant Monitoring Project
Dependencies: mbed SHT21_ncleee WakeUp SSD1306 DHT Adafruit_TCS34725 DS1820
Diff: main.cpp
- Revision:
- 12:ad8d26614e1e
- Parent:
- 11:5106c3ecc4d5
- Child:
- 13:80730bea52de
--- a/main.cpp Tue Oct 15 13:55:45 2019 +0000 +++ b/main.cpp Tue Oct 15 15:48:58 2019 +0000 @@ -3,7 +3,9 @@ #include "SHT21_ncleee.h" #include "Adafruit_TCS34725.h" #include "ssd1306.h" -#include "WakeUp.h" + +#define DUREE_MESURE 10 // Durée en seconde entre deux mesures +#define DUREE_ECRAN_ON 30 // Durée en seconde d'éveil de l'écran #define I2C_SDA D4 #define I2C_SCL D5 @@ -14,6 +16,9 @@ I2C i2c(I2C_SDA, I2C_SCL); SSD1306 oled(I2C_SDA, I2C_SCL); +Ticker timeScreen; +Ticker capture; + // capteur temperature sol DS1820 DS(D3); @@ -32,6 +37,9 @@ //Interruption Bouton InterruptIn bouton(D12); +// Flag OLED on +bool oled_on = 0; + // Définition de fonctions float temp_sol(void); int fct_humidity_sol(void); @@ -39,7 +47,8 @@ void sendDataSigfox(void); void oledData(void); void readData(void); -void interruption_bouton(void); +void interruption_bouton(void); +void turnOffScreen(void); float temperature_sol; unsigned char humidity_sol; @@ -50,32 +59,29 @@ int main() { - // Initialisation de l'écran - oled.speed (SSD1306::Medium); + // Affichage logo pour initialisation + oled.on(); oled.init(); + oled.cls(0,1); + oled.locate(4,4); + oled.printf("2PA2S"); + oled.redraw(); + wait(1); oled.cls(); - oled.set_contrast(200); - + oled.off(); + // Initialisation des mesures + capture.attach(&readData,DUREE_MESURE); + // Initialisation capteur lumière + if (!RGBsens.begin()) + { + pc.printf("No TCS34725 found ... check your connections"); + while (1); // halt! + } //Initialisation de l'interruption bouton.fall(interruption_bouton); + readData(); - // Initialisation WakeUp - //WakeUp::calibrate(); - //WakeUp::set(10); // Durée entre deux envois à modifier - //WakeUp::attach(&readData); - while(1) { - - // Mesures des grandeurs physiques - readData(); - - // Affichage des données sur l'écran - oledData(); - - // Envoi des données sur le cloud - sendDataSigfox(); - - wait(10); } } @@ -84,7 +90,7 @@ { DS.convertTemperature(true, DS1820::all_devices); if (DS.unassignedProbe(D3)){ - //pc.printf( "D3 not assigned\n\r"); + pc.printf( "D3 not assigned\n\r"); } return DS.temperature(); } @@ -103,11 +109,7 @@ { int somme; uint16_t clear, red, green, blue; - if (!RGBsens.begin()) - { - //pc.printf("No TCS34725 found ... check your connections"); - while (1); // halt! - } + RGBsens.getRawData(&red, &green, &blue, &clear); somme = red + green + blue; pr = red*100/somme; @@ -125,7 +127,16 @@ } void oledData(void){ - oled.cls(); + if(!oled_on){ + pc.printf("Turning on screen\n\r"); + oled.on(); + oled.speed (SSD1306::Medium); + oled.init(); + oled.set_contrast(200); + oled_on = 1; + } + pc.printf("Displaying data\n\r"); + oled.cls(0,1); oled.locate(0,0); oled.printf("AIR T : %.1f", temperature_air); oled.locate(1,0); @@ -138,21 +149,38 @@ oled.printf("Light : %d", lum); oled.locate(7,0); oled.printf("R %d G %d B %d", pr, pg, pb); - oled.redraw(); } void readData(void){ + pc.printf("reading data\n\r"); temperature_sol = temp_sol(); humidity_sol = fct_humidity_sol(); temperature_air = sht.readTemp(); humidity_air = sht.readHumidity(); - fct_RGB(); + //fct_RGB(); + sendDataSigfox(); + if(oled_on) + oledData(); } void interruption_bouton(){ - static int interruption_cpt = 0; - pc.printf("interruption %d\n\r", interruption_cpt++); + bouton.disable_irq(); + if(!oled_on){ + pc.printf("Interruption avec ecran eteint\n\r"); + oledData(); + timeScreen.attach(&turnOffScreen,DUREE_ECRAN_ON); + } + else{ + pc.printf("Interruption avec ecran allume\n\r"); + readData(); + } + bouton.enable_irq(); } - +void turnOffScreen(void){ + pc.printf("Extinction ecran\n\r"); + timeScreen.detach(); + oled_on = 0; + oled.off(); +}