Programme qui permet d'afficher la température en temps réel, grâce au capteur MCP9808 sur un microcontrôleur DISCO-F746NG. Le projet à été réalisé durant les cours d'interfaçage , en licence pro MECSE à l'IUT de Cachan.

Dependencies:   TS_DISCO_F746NG mbed LCD_DISCO_F746NG BSP_DISCO_F746NG MCP9808 BUTTON_GROUP

Files at this revision

API Documentation at this revision

Comitter:
Lio93
Date:
Tue Jun 04 14:36:02 2019 +0000
Parent:
12:e2bb579c4455
Commit message:
final

Changed in this revision

MCP9808.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MCP9808.lib	Tue Jun 04 14:36:02 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/stumpi/code/MCP9808/#f8e8cccfd476
--- a/main.cpp	Mon Feb 22 13:40:13 2016 +0000
+++ b/main.cpp	Tue Jun 04 14:36:02 2019 +0000
@@ -5,89 +5,95 @@
 //---------------------------------------------------------------
 
 #include "button_group.hpp"
+#include "MCP9808.h"
 
 using namespace Mikami;
 
 TS_DISCO_F746NG ts_;
 LCD_DISCO_F746NG lcd_;
+Serial pc(USBTX, USBRX); // tx, rx
+MCP9808 capteur(D14, D15); //: i2c(sda, scl)
 
 int main()
-{
+{ // ---------------------------------------INITIALISATION DES VARIABLES---------------------------------------------------
+    float temperature, kelvin, fahrenheit;
     const int Y0 = 5;
     const int X1 = 30;
     const int Y1 = 100;
+    int mode = 0;
 
-    const uint32_t BACK_COLOR = 0xFF006A6C;             // teal green
-    const uint32_t INACTIVE = BACK_COLOR & 0xE0FFFFFF;  // color for inactive button
+    const uint32_t BACK_COLOR = 0xFF006A6C;             // fond blue
     lcd_.Clear(BACK_COLOR);
        
-    const int NUMBER_BUTTONS = 4;
-    const string STR[NUMBER_BUTTONS] = {"Button1", "Button2", "Button3", "Button4"};
-    ButtonGroup bGroup(lcd_, ts_, 10, Y0, 66, 40,
-                       LCD_COLOR_BLUE, BACK_COLOR, NUMBER_BUTTONS, STR, 5, 5, 3);
-                       
-    const string STR_SW[2] = {"ON", "OFF"};
-    ButtonGroup sw(lcd_, ts_, 10, 160, 66, 40,
-                   LCD_COLOR_GREEN, BACK_COLOR, 2, STR_SW, 5, 0, 2);
-                       
-    Button reset(lcd_, ts_, 410, Y0, 60, 40,
-                 LCD_COLOR_BLUE, BACK_COLOR, "Reset", Font12);
-    reset.Draw(INACTIVE, LCD_COLOR_GRAY);
-
-    const string MULTI[2] = {"ON", "OFF"};
-    ButtonGroup multiTouch(lcd_, ts_, 300, Y0+100, 60, 40,
-                 LCD_COLOR_BLUE, BACK_COLOR, 2, MULTI, 5, 0, 2);
-    multiTouch.Draw(0, LCD_COLOR_DARKBLUE);
-
-    lcd_.SetTextColor(LCD_COLOR_WHITE);
-    lcd_.SetFont(&Font16);
-    lcd_.DisplayStringAt(250, Y0+80, (uint8_t *)"Multi-touch ON, OFF", LEFT_MODE);
-
-    lcd_.SetFont(&Font20);
-    lcd_.DisplayStringAt(120, 250, (uint8_t *)"02/22 22:36", LEFT_MODE);
+    const int NUMBER_BUTTONS = 3;   // nb de bouton
+    const string STR[NUMBER_BUTTONS] = {"KELVIN", "CELSIUS", "FAHRENHEIT"};
+    ButtonGroup bGroup(lcd_, ts_, 10, Y0, 100, 40,
+                       LCD_COLOR_BLUE, BACK_COLOR, NUMBER_BUTTONS, STR, 5, 5, 3); // 100 taille de la case
         
     DigitalOut dOut(D7);
     int num;
-
+//--------------------------------------------------------------------------------------------------------------------------
     while (true)
     {
+        temperature =capteur.readTemp(); // reception de la valeur de la temperature
+        fahrenheit = (temperature*9/5) + 32; // convertion
+        kelvin = temperature +273.15;       // convertion
+        
+        lcd_.DisplayStringAt(30, 200, (uint8_t *)"Medzo Owono Lionel", LEFT_MODE);
+        lcd_.DisplayStringAt(30, 230, (uint8_t *)"Capteur de temperature", LEFT_MODE);
+        
         dOut = 1;
-        bool touched = bGroup.GetTouchedNumber(num, LCD_COLOR_DARKBLUE);
+        bool touched = bGroup.GetTouchedNumber(num, LCD_COLOR_DARKBLUE); // bouton actionné change de couleur
         dOut = 0;
-        
+        char str[20];
         if (touched)
         {
-            char str[20];
+            
             lcd_.SetFont(&Font16);
             lcd_.SetTextColor(LCD_COLOR_WHITE);
-            sprintf(str, "Button%d pressed", num+1);
-            lcd_.DisplayStringAt(X1, Y1, (uint8_t *)str, LEFT_MODE);
             
-            reset.Redraw();
+           if (num==0) // choix du mode  1pour ensuite aller au switch case coorespondant
+            {
+                mode = 1;
+                lcd_.DisplayStringAt(X1, Y1, (uint8_t *)"                ", CENTER_MODE); c
+                
+            }
+            else if (num==1) //  choix du mode  2 pour ensuite aller au switch case coorespondant
+            {
+                mode = 2;
+                lcd_.DisplayStringAt(X1, Y1, (uint8_t *)"                ", CENTER_MODE);// effacer l'ecriture précedente
+            }
+            else if (num==2) // choix du mode 3 pour ensuite aller au switch case coorespondant
+            {
+                mode = 3;
+                lcd_.DisplayStringAt(X1, Y1, (uint8_t *)"                ", CENTER_MODE);// effacer l'ecriture précedente
+            }
+           
+            
         }
         
-        if (sw.Touched(0, LCD_COLOR_DARKGREEN))
-            lcd_.DisplayStringAt(X1, 210, (uint8_t *)"ON ", LEFT_MODE);
-        if (sw.Touched(1, LCD_COLOR_DARKGREEN))
-            lcd_.DisplayStringAt(X1, 210, (uint8_t *)"OFF", LEFT_MODE);
-        
-        if (reset.Touched())
-        {
-            bGroup.Redraw(num);
-            reset.Draw(INACTIVE, LCD_COLOR_GRAY);
-            lcd_.SetFont(&Font16);
-            lcd_.DisplayStringAt(X1, Y1, (uint8_t *)"               ", LEFT_MODE);
-        }
-        
-        int mNum;
-        if (multiTouch.GetTouchedNumber(mNum, LCD_COLOR_DARKBLUE))
-        {
-            Button::SetMultiTouch(mNum == 0);   // Set or reset multi-touch
-            if (mNum == 0)
-                lcd_.DisplayStringAt(320, Y0+150, (uint8_t *)"ON ", LEFT_MODE);
-            else
-                lcd_.DisplayStringAt(320, Y0+150, (uint8_t *)"OFF", LEFT_MODE);
-        }
+         switch (mode){ //  choix du mode, avec affichage en continue 
+                case 1:
+                    
+                    
+                    sprintf(str, "%.2f K", kelvin);
+                    lcd_.DisplayStringAt(X1, Y1, (uint8_t *)str, CENTER_MODE);
+                    break;
+                    
+                case 2:
+                    
+                    
+                    sprintf(str, "%.2f C", temperature);
+                    lcd_.DisplayStringAt(X1, Y1, (uint8_t *)str, CENTER_MODE);
+                    break;
+                    
+                case 3:
+                    
+                    
+                    sprintf(str, "%.2f F",fahrenheit );
+                    lcd_.DisplayStringAt(X1, Y1, (uint8_t *)str, CENTER_MODE);
+                    break;
+                }
         wait(0.01f);
     }
 }