Projet Long pour AGRAL

Dependencies:   mbed OneWire DHT22 TSL2561 SSD1306

Files at this revision

API Documentation at this revision

Comitter:
pgeorge
Date:
Mon Jan 15 13:34:04 2018 +0000
Parent:
11:7c872ac9da9a
Commit message:
fix addr lux

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Mon Nov 20 15:33:30 2017 +0000
+++ b/main.cpp	Mon Jan 15 13:34:04 2018 +0000
@@ -6,7 +6,7 @@
                 Humidité de l'air, Température du sol 
                 et Huminidité du sol.
                 Affichage dans la console et sur l'écran
-                OLED, ainsi que envoie sur le site 
+                OLED, envoie sur le site 
                 ACTOBOARD via module Sigfox. 
 Auteur ...... : GEORGE Pierre, LOUVION Quentin et 
                 FAISANT Pierre-Yves
@@ -22,7 +22,7 @@
 #include "bold_font.h"
 
 //Déclaration variables
-TSL2561 Lum(PB_7,PB_6); // Luminosité (I2C:SDA,SCL)
+TSL2561 Lum(PB_7,PB_6,0x39); // Luminosité (I2C:SDA,SCL)
 DHT22 Tem_Hum_A(PA_11); // Température & Humidité air
 OneWire Tem_S(PA_8); // Température sol
 AnalogIn Hum_S(PA_0); // Huminidité sol
@@ -31,17 +31,24 @@
 Serial sigfox(PA_9,PA_10,9600); // Module Sigfox
 LowPowerTicker t1; // Ticker pour la fonction d'interruption
 
+DigitalIn btn(D6);//button
+InterruptIn button(D6);
+
+
+
+
 char _id[16];
 DeviceAddresses* devAddresses;
 uint8_t foundNum;
 
-volatile uint8_t flag=1;
+volatile uint8_t flag=1,flag_screen=0;
 
 void run() 
 {
     I2C i2c(PB_7,PB_6);
-        
+        Lum.power_up();
     //OneWire Tem_S
+    wait_ms(400);
     OneWireDeviceTemperature::startConversationForAll(&Tem_S, OWTEMP_11_BIT);
     for (uint8_t i = 0; i < foundNum; i++) 
     {
@@ -75,6 +82,58 @@
         
         // Affichage données, mises en forme, sur l'écran OLED
         wait(2);
+        
+        Lum.power_down();
+    }
+}
+void interruption(){
+    flag=1;
+    }
+void int_screen()
+{
+    flag_screen = 1;    
+}
+void screen()
+{
+    oled.initialise();
+    oled.clear();
+    oled.set_contrast(255); // max contrast
+ 
+    oled.set_font(bold_font, 8);
+    I2C i2c(PB_7,PB_6);
+        Lum.power_up();
+    //OneWire Tem_S
+    wait_ms(600);
+    OneWireDeviceTemperature::startConversationForAll(&Tem_S, OWTEMP_11_BIT);
+    for (uint8_t i = 0; i < foundNum; i++) 
+    {
+        OneWireDevice* owDevice = OneWireDeviceFactory::init(&Tem_S, (*devAddresses)[i]);
+        
+        if (owDevice->getFamily() != ONEWIRE_DS18B20_FAMILY)    // currently only DS18B20 supports
+            continue;
+
+        owDevice->generateId(_id);
+        
+        Tem_Hum_A.sample();
+
+        // Calcul sur les données envoyées par les capteurs
+        float Lumux = Lum.lux();
+        float Temp_Air = Tem_Hum_A.getTemperature()/10.0;
+        float Hum_Air = Tem_Hum_A.getHumidity()/10.0;
+        float Temp_Sol = owDevice->sendGetCommand(GET_TEMPERATURE);
+        float Hum_Sol = Hum_S.read();
+        
+       
+        
+
+        
+        delete owDevice;   
+         
+        SPI spi(PA_7,NC, PA_5);
+        
+        // Affichage données, mises en forme, sur l'écran OLED
+        wait(2);
+        printf( "Lum: %.2f \tTemp_A: %.2f \tHum_A: %.2f \tTemp_S: %.2f \tHum_S: %.2f\r\n", Lumux, Temp_Air, Hum_Air, Temp_Sol, Hum_Sol);
         oled.set_font(bold_font, 8);
         oled.printf("Capteurs\r\n");
         oled.printf("\r\n");
@@ -86,12 +145,13 @@
         oled.printf("Hum_S: %.2f\r\n", Hum_Sol);
         oled.printf("\r\n");
         oled.update();
+        Lum.power_down();
     }
+    wait(5);
+    oled.off();
+   
+        
 }
-void interruption(){
-    flag=1;
-    }
-    
 int main() {
     //OneWire Tem_S
     I2C i2c(PB_7,PB_6);
@@ -114,8 +174,11 @@
 
     oled.update();
     
-    t1.attach(interruption,61);
-    
+    //t1.attach(interruption,61);
+    t1.attach(interruption,5);
+    btn.mode(PullUp);
+    button.rise(&int_screen);  // attach the address of screen
+    //run();
     while(1) 
     {
         if(flag)
@@ -123,6 +186,11 @@
             run();
             flag=0;
         }
+        else if(flag_screen)
+        {
+            screen();
+            flag_screen=0;
+        }
         deepsleep();
     }
 }