Plant Monitoring Project

Dependencies:   mbed SHT21_ncleee WakeUp SSD1306 DHT Adafruit_TCS34725 DS1820

Revision:
16:13364798fce6
Parent:
15:c73d0d180cc4
Child:
17:7d07f5f0f033
--- a/main.cpp	Mon Oct 21 08:38:11 2019 +0000
+++ b/main.cpp	Tue Oct 22 14:33:22 2019 +0000
@@ -4,14 +4,11 @@
 #include "Adafruit_TCS34725.h"
 #include "ssd1306.h"
 
-#define I2C_SDA D12
-#define I2C_SCL A6
-
 //Serial pc(SERIAL_TX, SERIAL_RX);
 Serial nucleo(D1,D0);
 
 I2C i2c(D4, D5);
-SSD1306 oled(I2C_SDA, I2C_SCL);
+SSD1306 oled(D12, A6);
 
 // capteur temperature sol
 DS1820 DS(D3); 
@@ -32,46 +29,30 @@
 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    sendDataSigfox(float tempSol, unsigned char *humSol, float tempAir, unsigned char *humAir, unsigned short *lux, unsigned char *R, unsigned char *G, unsigned char *B);
+void    sendDataSigfox(void);
 void    oledData(void);
+void    readData(void);
 
 
-    float temperature_sol;
-    unsigned char humidity_sol;
-    float temperature_air;
-    unsigned char humidity_air;
-    unsigned char pr, pg, pb;
-    unsigned short lum;
+float temperature_sol;
+unsigned char humidity_sol;
+float temperature_air;
+unsigned char humidity_air;
+unsigned char pr, pg, pb;
+unsigned short lum;
     
     
 int main() {
-    oled.speed (SSD1306::Medium);  // set working frequency
-    oled.init();                   // initialize SSD1306
-    oled.cls();                    // clear frame buffer
+    oled.speed (SSD1306::Medium);
+    oled.init();
+    oled.cls(0,1);
     oled.set_contrast(200);
         
     while(1) {
-      
-      temperature_sol = temp_sol();
-      //pc.printf("T sol = %.2f\n\r", temperature_sol);
-      
-      humidity_sol = fct_humidity_sol();
-      //pc.printf("H sol = %d\n\r", humidity_sol);
-      
-      temperature_air = sht.readTemp();
-      //pc.printf("temperature_air = %.2f\n\r", temperature_air);
-      
-      humidity_air = sht.readHumidity();
-      //pc.printf("humidity_air = %d\n\r", humidity_air);
-      
-      fct_RGB(&pr, &pg, &pb, &lum);
-      //pc.printf("red=%d green=%d blue=%d\n\r", pr, pg, pb);
         
+      readData();
       oledData();
-      sendDataSigfox(temperature_sol, &humidity_sol, temperature_air, &humidity_air, &lum, &pr, &pg, &pb);
-    
-      //pc.printf("\n\r");
-      wait(10);
+      wait(3);
     }
 }
 
@@ -112,18 +93,16 @@
         *lux = clear;
 }
 
-void sendDataSigfox(float tempSol, unsigned char *humSol, float tempAir, unsigned char *humAir, unsigned short *lux, unsigned char *R, unsigned char *G, unsigned char *B){
-        short tempSol_short, tempAir_short;
-        tempSol *= 10;
-        tempAir *= 10;
-        tempSol_short = (short) tempSol;
-        tempAir_short = (short) tempAir;
+void sendDataSigfox(void){
+    short tempSol_short, tempAir_short;
+    tempSol_short = (short)(temperature_sol*10);
+    tempAir_short = (short)(temperature_air*10);
 
-        nucleo.printf("AT$SF=%04x%02x%04x%02x%04x%02x%02x%02x\r\n",tempSol_short, *humSol, tempAir_short, *humAir, *lux, *R, *G, *B);
-    }
+    nucleo.printf("AT$SF=%04x%02x%04x%02x%04x%02x%02x%02x\r\n",tempSol_short, humidity_sol, tempAir_short, humidity_air, lum, pr, pg, pb);
+}
     
 void oledData(void){
-    oled.cls();
+    oled.cls(0,1);
     oled.locate(0,0);
     oled.printf("AIR T : %.1f", temperature_air);
     oled.locate(1,0);
@@ -140,4 +119,13 @@
     oled.redraw();
 }
 
+void readData(void){
+    temperature_sol = temp_sol();
+    humidity_sol = fct_humidity_sol();
+    temperature_air = sht.readTemp();      
+    humidity_air = sht.readHumidity();      
+    fct_RGB(&pr, &pg, &pb, &lum);
+    sendDataSigfox();
+}
 
+