Programme du projet interfacage : Detecteur de couleur QUINQUIRY Guillaume LPRO MECSE

Dependencies:   mbed APDS_9960 BSP_DISCO_F746NG

Files at this revision

API Documentation at this revision

Comitter:
guillaumequinquiry
Date:
Thu Jun 24 12:00:03 2021 +0000
Commit message:
Programme interfacage QUINQUIRY Guillaume

Changed in this revision

APDS_9960.lib Show annotated file Show diff for this revision Revisions of this file
BSP_DISCO_F746NG.lib Show annotated file Show diff for this revision Revisions of this file
capteurcouleurmain.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/APDS_9960.lib	Thu Jun 24 12:00:03 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/guillaumequinquiry/code/APDS_9960/#6f662fad61f5
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/BSP_DISCO_F746NG.lib	Thu Jun 24 12:00:03 2021 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/teams/ST/code/BSP_DISCO_F746NG/#85dbcff443aa
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/capteurcouleurmain.cpp	Thu Jun 24 12:00:03 2021 +0000
@@ -0,0 +1,234 @@
+#include "mbed.h" // Bibliothèque mbed intialement dans le programme 
+#include "stm32746g_discovery_lcd.h" // bibliothèque pour les fonctions de l’écran lcd (graphique)
+#include "stm32746g_discovery_ts.h" //  bibliothèque pour les fonctions de l’écran lcd (tactile)
+#include "stm32746g_discovery.h" //  bibliothèque pour les fonctions de la carte stm32746g
+#include "glibr.h" // bibiliothèque pour les fonctions des capteurs de l'APDS9960 
+
+// Masques pour le capteur de couleur  donc la valeur est codée sur 16 bits 
+#define HIGH 0xFF00
+#define LOW  0x00FF
+
+int main()
+{
+    glibr ColorSensor(PB_9,PB_8); // bus I2C broches sda, scl
+    InterruptIn interrupt(PA_8); // broche d'interruption
+    Serial pc(USBTX, USBRX); // définition du port usb 
+    uint16_t light, r, b, g; // Variable contenant les couleurs pour le rouge,vert,bleu 
+    uint8_t text[30], text1[30],text2[30], text3[30], text4[30],p;// Variable pour pouvoir afficher les valeurs sur l'écran LCD
+    char rouge[500], vert[500], bleu[500];
+    TS_StateTypeDef  TS_State = {0}; // Variable comprenant l'état de l'écran tactile
+    int touchScreen=1; // 
+    
+    BSP_LCD_Init(); // initialisation de l'écran LCD
+    BSP_LCD_LayerDefaultInit(0, LCD_FB_START_ADDRESS);
+    BSP_LCD_SelectLayer(0);
+    
+    /* Initialisation de l'écran tactile  */
+    if (BSP_TS_Init(BSP_LCD_GetXSize(), BSP_LCD_GetYSize()) == TS_ERROR) {
+        printf("BSP_TS_Init error\n");
+    }
+    
+    /* Mise à blanc de l'écran tactile  */
+    BSP_LCD_Clear(LCD_COLOR_WHITE);
+ 
+    /* Affichage de l'interface d'entrée  */
+    BSP_LCD_SetTextColor(LCD_COLOR_BLUE);
+    BSP_LCD_FillRect(0, 0, BSP_LCD_GetXSize(), 40);
+    BSP_LCD_SetTextColor(LCD_COLOR_DARKMAGENTA);
+    BSP_LCD_FillRect(0, 40, BSP_LCD_GetXSize(), 40);
+    BSP_LCD_SetTextColor(LCD_COLOR_DARKGREEN);
+    BSP_LCD_FillRect(0, 80, BSP_LCD_GetXSize(), 45);
+    BSP_LCD_SetTextColor(LCD_COLOR_BLACK);
+    BSP_LCD_SetBackColor(LCD_COLOR_GREEN);
+    BSP_LCD_SetFont(&Font24);
+    BSP_LCD_DisplayStringAt(0, 125, (uint8_t *)"Color Sensor, Touch to start", CENTER_MODE); // Affichage sur l'écran 
+    BSP_LCD_SetTextColor(LCD_COLOR_YELLOW);
+    BSP_LCD_FillRect(0, 148, BSP_LCD_GetXSize(), 45);
+    BSP_LCD_SetTextColor(LCD_COLOR_ORANGE);
+    BSP_LCD_FillRect(0, 193, BSP_LCD_GetXSize(), 42);
+    BSP_LCD_SetTextColor(LCD_COLOR_RED);
+    BSP_LCD_FillRect(0, 235, BSP_LCD_GetXSize(), 40);
+    
+    while(touchScreen)
+    {
+        BSP_TS_GetState(&TS_State);
+        if (TS_State.touchDetected)
+        {
+            touchScreen=0; // Mise à 0 de la variable lors d'un appui sur l'écran
+        }
+    }
+    
+    /* Initialisation de l'APPDS et de l'ensemble de ses capteurs*/
+    if ( ColorSensor.ginit() ) {
+        pc.printf("APDS-9960 initialization complete\n\r");
+    } else {
+        pc.printf("Something went wrong during APDS-9960 init\n\r");
+    }
+        while(1)
+        {
+            BSP_TS_GetState(&TS_State); // récupération de l'état de l'écran
+            if (TS_State.touchDetected) // si appui tactile sur l'écran
+            {
+                BSP_LCD_Clear(LCD_COLOR_WHITE);
+                BSP_LCD_SetTextColor(LCD_COLOR_BLACK);
+                BSP_LCD_SetFont(&Font24);
+                BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
+                BSP_LCD_DisplayStringAt(0, 60, (uint8_t *)"Couleur detecte : ", CENTER_MODE); // affichage de l'application 
+            }
+            
+            if ( ColorSensor.enableLightSensor(true) and  ColorSensor.enableProximitySensor(true) and  touchScreen == 0  ) // Utilisation des capteurs de couleur et de proximité 
+            {
+                ColorSensor.readAmbientLight(light); // Fonction permettant de récupérer la valeur de la luminosité ambiante détecté par le capteur de lumiere
+                /* Fonctions permettant de récupérer les  valeurs des couleurs  RGB rouge,vert,bleu détecté par le capteur de couleur/lumiere */
+                ColorSensor.readRedLight(r); 
+                ColorSensor.readGreenLight(g);
+                ColorSensor.readBlueLight(b);
+                //Fonction permettant de récupérer la valeur de la proximité d'un objet avec le capteur de proximité 
+                ColorSensor.readProximity(p);
+                
+                //Lecture des deux octets pour la couleur
+                /*rouge[0]= (char)((r & HIGH)>>8);  // affiche 0
+                rouge[1]= (char) (r & LOW); // affiche la même valeur que si on affiche directement r
+                i2c.read(0x39,data,2);
+                sprintf((char *) lumiere,data);
+                vert[0]= (char)((g & HIGH)>>8); 
+                vert[1]= (char) (g & LOW);                      
+                bleu[0]= (char)((b & HIGH)>>8);
+                bleu[1]= (char) (g & LOW);
+                sprintf((char *)test, "%d ", rouge[0]);
+                pc.printf("\nRed = ");
+                pc.printf((char *)lumiere);*/
+                
+                BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
+                BSP_LCD_SetTextColor(LCD_COLOR_BLACK);
+                BSP_LCD_SetFont(&Font24);
+                
+                // conversion des valeurs uint 16 en char pour affichage sur l'écran LCD 
+                sprintf((char *)text,"Lum = %d", light); 
+                pc.printf((char *)text);
+                BSP_LCD_DisplayStringAt(70, 200, (uint8_t *)text, CENTER_MODE);
+                BSP_LCD_SetTextColor(LCD_COLOR_RED);
+                sprintf((char *)text1, "R = %d", r);
+                pc.printf((char *)text1);
+                BSP_LCD_DisplayStringAt(40, 175, (uint8_t *)text1, LEFT_MODE);
+                BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
+                sprintf((char *)text2, "V = %d", g);
+                pc.printf((char *)text2);
+                BSP_LCD_DisplayStringAt(40, 200, (uint8_t *)text2, LEFT_MODE);
+                BSP_LCD_SetTextColor(LCD_COLOR_BLUE);
+                sprintf((char *)text3, "B = %d", b);
+                pc.printf((char *)text3);
+                BSP_LCD_DisplayStringAt(40, 225, (uint8_t *)text3, LEFT_MODE);
+                sprintf((char *)text4, "%d", p);
+                pc.printf("\nProximite = ");
+                pc.printf((char *)text4);
+                
+                /* Début des conditions pour afficher les différentes couleurs en fonction des valeurs rgb du capteur */
+                
+                if(r == 0 and g ==0 and b == 0)// si aucune couleur détecté =>  Couleur Noir 
+                {
+                    BSP_LCD_SetTextColor(LCD_COLOR_BLACK);
+                    BSP_LCD_FillRect(0, 0, 45, 45);
+                    BSP_LCD_FillRect(435, 0, 45, 45);
+                    BSP_LCD_SetFont(&Font24);
+                    BSP_LCD_DisplayStringAt(0, 125, (uint8_t *)"Noir  ", CENTER_MODE);
+                }
+                
+                if(b > g and g > r)// si bleu > vert > rouge  =>  Couleur Bleu
+                {
+                    BSP_LCD_SetTextColor(LCD_COLOR_BLUE);
+                    BSP_LCD_FillRect(0, 0, 45, 45);
+                    BSP_LCD_FillRect(435, 0, 45, 45);
+                    BSP_LCD_SetFont(&Font24);
+                    BSP_LCD_DisplayStringAt(0, 125, (uint8_t *)"Bleu  ", CENTER_MODE);
+                }
+                
+                if (b > r and r > g) // si bleu > rouge > vert  => Couleur Violet 
+                {
+                    BSP_LCD_SetTextColor(LCD_COLOR_MAGENTA);
+                    BSP_LCD_FillRect(0, 0, 45, 45);
+                    BSP_LCD_FillRect(435, 0, 45, 45);
+                    BSP_LCD_SetFont(&Font24);
+                    BSP_LCD_DisplayStringAt(0, 125, (uint8_t *)"Violet", CENTER_MODE);
+                }
+                
+                if (r > g and g > b) // si rouge > vert > bleu   => Couleur Jaune
+                {
+                    BSP_LCD_SetTextColor(LCD_COLOR_YELLOW);
+                    BSP_LCD_FillRect(0, 0, 45, 45);
+                    BSP_LCD_FillRect(435, 0, 45, 45);
+                    BSP_LCD_SetFont(&Font24);
+                    BSP_LCD_DisplayStringAt(0, 125, (uint8_t *)"Jaune ", CENTER_MODE);
+
+                }
+                
+                if (r > g and g == b) // si rouge > vert=bleu   => Couleur Orange
+                {
+                    BSP_LCD_SetTextColor(LCD_COLOR_ORANGE);
+                    BSP_LCD_FillRect(0, 0, 45, 45);
+                    BSP_LCD_FillRect(435, 0, 45, 45);
+                    BSP_LCD_SetFont(&Font24);
+                    BSP_LCD_DisplayStringAt(0, 125, (uint8_t *)"Orange", CENTER_MODE);
+
+                }
+                
+                if (g > b and b > r) // si vert > bleu > rouge  => Couleur Verte
+                {
+                    BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
+                    BSP_LCD_FillRect(0, 0, 45, 45);
+                    BSP_LCD_FillRect(435, 0, 45, 45);
+                    BSP_LCD_SetFont(&Font24);
+                    BSP_LCD_DisplayStringAt(0, 125, (uint8_t *)"Vert  ", CENTER_MODE);
+                }
+                
+                if (r > b and b  > g) // si rouge > bleu > vert   => Couleur Rouge
+                                {
+                    BSP_LCD_SetTextColor(LCD_COLOR_RED);
+                    BSP_LCD_FillRect(0, 0, 45, 45);
+                    BSP_LCD_FillRect(435, 0, 45, 45);
+                    BSP_LCD_SetFont(&Font24);
+                    BSP_LCD_DisplayStringAt(0, 125, (uint8_t *)"Rouge ", CENTER_MODE);
+                }
+                if(b > g and g > r and b-g < 5 and g-r < 5 ) // si bleu > vert > rouge avec une très petite différence de valeur (inférieure à 5)  => Couleur Blanc
+                {
+                    BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
+                    BSP_LCD_FillRect(0, 0, 45, 45);
+                    BSP_LCD_FillRect(435, 0, 45, 45);
+                    BSP_LCD_SetTextColor(LCD_COLOR_BLACK);
+                    BSP_LCD_SetFont(&Font24);
+                    BSP_LCD_DisplayStringAt(0, 125, (uint8_t *)"Blanc ", CENTER_MODE);   
+                }
+                
+                /* Conditions d'affichage pour le capteur de proximité*/          
+                
+                if (p == 255) // si p= valeur max : objet trop loin du capteur 
+                {
+                    BSP_LCD_SetTextColor(LCD_COLOR_RED);
+                    BSP_LCD_DisplayStringAt(0, 10, (uint8_t *) "Objet trop pres", CENTER_MODE);
+                }
+                else if (p == 0) // si p = valeur min : objet trop proche du capteur 
+                {
+                    BSP_LCD_SetTextColor(LCD_COLOR_RED);
+                    BSP_LCD_DisplayStringAt(0, 10, (uint8_t *) "Objet trop loin", CENTER_MODE);
+                }
+                else if (0 < p < 255) // entre les deux valeurs, mesures possibles 
+                {
+                    BSP_LCD_SetTextColor(LCD_COLOR_RED);
+                    BSP_LCD_DisplayStringAt(0, 10, (uint8_t *) "               ", CENTER_MODE);
+                }  
+                
+                /* Conditions d'affichage pour le capteur de lumière ambiante*/ 
+                
+                if (light < 20 )// si la lumière est trop faible 
+                {
+                    BSP_LCD_SetTextColor(LCD_COLOR_BLACK);
+                    BSP_LCD_DisplayStringAt(70, 240, (uint8_t *) "Trop Faible", CENTER_MODE);
+                }  
+                else if (light > 20 )
+                {
+                    BSP_LCD_SetTextColor(LCD_COLOR_BLACK);
+                    BSP_LCD_DisplayStringAt(70, 240, (uint8_t *) "           ", CENTER_MODE);  
+                }
+        } 
+    } 
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Jun 24 12:00:03 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file