![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Plant Monitoring Project
Dependencies: mbed SHT21_ncleee WakeUp SSD1306 DHT Adafruit_TCS34725 DS1820
Diff: main.cpp
- Revision:
- 18:d30cd2967da4
- Parent:
- 17:7d07f5f0f033
- Child:
- 19:d6236253bf5f
--- a/main.cpp Tue Oct 22 14:34:11 2019 +0000 +++ b/main.cpp Tue Oct 22 15:19:31 2019 +0000 @@ -4,10 +4,15 @@ #include "Adafruit_TCS34725.h" #include "ssd1306.h" +#define DUREE_MESURE 3 // Durée en seconde entre deux mesures +#define DUREE_ECRAN_ON 10 // Durée en seconde d'éveil de l'écran + +Ticker timeScreen; + //Serial pc(SERIAL_TX, SERIAL_RX); Serial nucleo(D1,D0); -I2C i2c(D4, D5); +I2C i2c(D4, D5); // Pour les deux capteurs i2c SSD1306 oled(D12, A6); // capteur temperature sol @@ -22,20 +27,25 @@ // capteur RGB Adafruit_TCS34725 RGBsens = Adafruit_TCS34725(&i2c, TCS34725_INTEGRATIONTIME_154MS, TCS34725_GAIN_1X); -// capteur lumière -AnalogIn ain(A1); +//Interruption Bouton +InterruptIn bouton(D10); + +// Flag OLED state +bool oled_on = 0; // Définition de fonctions float temp_sol(void); int fct_humidity_sol(void); -void fct_RGB(unsigned char *pr, unsigned char *pg, unsigned char *pb, unsigned short *lux); +void fct_RGB(void); void sendDataSigfox(void); void oledData(void); void readData(void); +void interruption_bouton(void); +void turnOffScreen(void); float temperature_sol; -unsigned char humidity_sol; +unsigned char humidity_sol; float temperature_air; unsigned char humidity_air; unsigned char pr, pg, pb; @@ -43,16 +53,19 @@ int main() { + //Initialisation de l'interruption + bouton.fall(interruption_bouton); + oled.speed (SSD1306::Medium); oled.init(); oled.cls(0,1); oled.set_contrast(200); + oled.sleep(); while(1) { readData(); - oledData(); - wait(3); + wait(DUREE_MESURE); } } @@ -76,7 +89,7 @@ return (int) mesure_etalonnee; } -void fct_RGB(unsigned char *pr, unsigned char *pg, unsigned char *pb, unsigned short *lux) +void fct_RGB(void) { int somme; uint16_t clear, red, green, blue; @@ -87,10 +100,10 @@ } RGBsens.getRawData(&red, &green, &blue, &clear); somme = red + green + blue; - *pr = red*100/somme; - *pg = green*100/somme; - *pb = blue*100/somme; - *lux = clear; + pr = red*100/somme; + pg = green*100/somme; + pb = blue*100/somme; + lum = clear; } void sendDataSigfox(void){ @@ -102,6 +115,15 @@ } void oledData(void){ + if(!oled_on){ + //pc.printf("Turning on screen\n\r"); + oled.wake(); + //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); @@ -115,7 +137,6 @@ oled.printf("Light : %d", lum); oled.locate(7,0); oled.printf("R %d G %d B %d", pr, pg, pb); - oled.redraw(); } @@ -124,8 +145,29 @@ humidity_sol = fct_humidity_sol(); temperature_air = sht.readTemp(); humidity_air = sht.readHumidity(); - fct_RGB(&pr, &pg, &pb, &lum); + fct_RGB(); sendDataSigfox(); + if(oled_on) + oledData(); } +void interruption_bouton(){ + 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.sleep(); +}