Detection of CO and Methane
Dependencies: TS_DISCO_F746NG mbed LCD_DISCO_F746NG BSP_DISCO_F746NG BUTTON_GROUP
main.cpp@0:4e0085011ee0, 2019-06-04 (annotated)
- Committer:
- maria_launay
- Date:
- Tue Jun 04 14:49:28 2019 +0000
- Revision:
- 0:4e0085011ee0
Detection of CO and methane with the captor TGS3870-B00 and the board STM32F746G-DISCO
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
maria_launay | 0:4e0085011ee0 | 1 | //Détecteur de Co et Méthane |
maria_launay | 0:4e0085011ee0 | 2 | #include "mbed.h" |
maria_launay | 0:4e0085011ee0 | 3 | #include "LCD_DISCO_F746NG.h" |
maria_launay | 0:4e0085011ee0 | 4 | #include "TS_DISCO_F746NG.h" |
maria_launay | 0:4e0085011ee0 | 5 | #include "button_group.hpp" |
maria_launay | 0:4e0085011ee0 | 6 | |
maria_launay | 0:4e0085011ee0 | 7 | using namespace Mikami; |
maria_launay | 0:4e0085011ee0 | 8 | |
maria_launay | 0:4e0085011ee0 | 9 | LCD_DISCO_F746NG lcd; |
maria_launay | 0:4e0085011ee0 | 10 | TS_DISCO_F746NG ts; |
maria_launay | 0:4e0085011ee0 | 11 | |
maria_launay | 0:4e0085011ee0 | 12 | //Pins du capteur |
maria_launay | 0:4e0085011ee0 | 13 | AnalogIn sensorElectrode (PA_0); |
maria_launay | 0:4e0085011ee0 | 14 | AnalogIn heater (PF_10); |
maria_launay | 0:4e0085011ee0 | 15 | |
maria_launay | 0:4e0085011ee0 | 16 | int main() { |
maria_launay | 0:4e0085011ee0 | 17 | |
maria_launay | 0:4e0085011ee0 | 18 | //Déclaration des variables |
maria_launay | 0:4e0085011ee0 | 19 | DigitalOut dOut(D7); |
maria_launay | 0:4e0085011ee0 | 20 | int num, bouton; |
maria_launay | 0:4e0085011ee0 | 21 | const int X1 = 20; |
maria_launay | 0:4e0085011ee0 | 22 | const int X2 = 200; |
maria_launay | 0:4e0085011ee0 | 23 | const int Y1 = 100; |
maria_launay | 0:4e0085011ee0 | 24 | const int Y2 = 150; |
maria_launay | 0:4e0085011ee0 | 25 | const int Y3 = 200; |
maria_launay | 0:4e0085011ee0 | 26 | const int Y4 = 250; |
maria_launay | 0:4e0085011ee0 | 27 | float broche1; |
maria_launay | 0:4e0085011ee0 | 28 | float broche2; |
maria_launay | 0:4e0085011ee0 | 29 | |
maria_launay | 0:4e0085011ee0 | 30 | char str[50]; |
maria_launay | 0:4e0085011ee0 | 31 | char text[50]; |
maria_launay | 0:4e0085011ee0 | 32 | char broche [50]; |
maria_launay | 0:4e0085011ee0 | 33 | char attention[50]; |
maria_launay | 0:4e0085011ee0 | 34 | |
maria_launay | 0:4e0085011ee0 | 35 | const uint32_t BACK_COLOR = 0xFF006A6C; |
maria_launay | 0:4e0085011ee0 | 36 | lcd.Clear(BACK_COLOR); |
maria_launay | 0:4e0085011ee0 | 37 | |
maria_launay | 0:4e0085011ee0 | 38 | //Déclaration des boutons |
maria_launay | 0:4e0085011ee0 | 39 | const string STR[3] = {"CO","Methane","Les deux"}; |
maria_launay | 0:4e0085011ee0 | 40 | ButtonGroup bGroup(lcd, ts, 140, 10, 66, 40, |
maria_launay | 0:4e0085011ee0 | 41 | LCD_COLOR_LIGHTBLUE, BACK_COLOR, 3, STR, 5, 5, 3); |
maria_launay | 0:4e0085011ee0 | 42 | |
maria_launay | 0:4e0085011ee0 | 43 | //Affichage de départ |
maria_launay | 0:4e0085011ee0 | 44 | sprintf(str, "Aucune recherche en cours "); |
maria_launay | 0:4e0085011ee0 | 45 | sprintf(text, "Broche 1 = %0.2f Broche 2 = %0.2f", broche1, broche2); |
maria_launay | 0:4e0085011ee0 | 46 | sprintf(broche, " "); |
maria_launay | 0:4e0085011ee0 | 47 | sprintf(attention, " "); |
maria_launay | 0:4e0085011ee0 | 48 | |
maria_launay | 0:4e0085011ee0 | 49 | while(true) |
maria_launay | 0:4e0085011ee0 | 50 | { |
maria_launay | 0:4e0085011ee0 | 51 | //Vérification des valeurs |
maria_launay | 0:4e0085011ee0 | 52 | broche1 = sensorElectrode; |
maria_launay | 0:4e0085011ee0 | 53 | broche2 = heater; |
maria_launay | 0:4e0085011ee0 | 54 | lcd.DisplayStringAt(X1, Y1, (uint8_t *)str, LEFT_MODE); |
maria_launay | 0:4e0085011ee0 | 55 | lcd.DisplayStringAt(X1, Y2, (uint8_t *)text, LEFT_MODE); |
maria_launay | 0:4e0085011ee0 | 56 | lcd.DisplayStringAt(X1, Y3, (uint8_t *)broche, LEFT_MODE); |
maria_launay | 0:4e0085011ee0 | 57 | lcd.DisplayStringAt(X2, Y4, (uint8_t *)attention, LEFT_MODE); |
maria_launay | 0:4e0085011ee0 | 58 | |
maria_launay | 0:4e0085011ee0 | 59 | //Valeur des broches du capteur |
maria_launay | 0:4e0085011ee0 | 60 | sprintf(text, "Broche 1 = %0.2f Broche 2 = %0.2f", broche1, broche2); |
maria_launay | 0:4e0085011ee0 | 61 | |
maria_launay | 0:4e0085011ee0 | 62 | dOut = 1; |
maria_launay | 0:4e0085011ee0 | 63 | bool touched = bGroup.GetTouchedNumber(num, LCD_COLOR_LIGHTRED); |
maria_launay | 0:4e0085011ee0 | 64 | dOut = 0; |
maria_launay | 0:4e0085011ee0 | 65 | |
maria_launay | 0:4e0085011ee0 | 66 | //Appuie des boutons |
maria_launay | 0:4e0085011ee0 | 67 | if (touched) |
maria_launay | 0:4e0085011ee0 | 68 | { |
maria_launay | 0:4e0085011ee0 | 69 | lcd.DisplayStringAt(X1, Y1, (uint8_t *)" ", LEFT_MODE); |
maria_launay | 0:4e0085011ee0 | 70 | lcd.SetFont(&Font16); |
maria_launay | 0:4e0085011ee0 | 71 | lcd.SetTextColor(LCD_COLOR_WHITE); |
maria_launay | 0:4e0085011ee0 | 72 | bouton = num +1; |
maria_launay | 0:4e0085011ee0 | 73 | } |
maria_launay | 0:4e0085011ee0 | 74 | |
maria_launay | 0:4e0085011ee0 | 75 | //Affichage du résultat de la détection du gaz |
maria_launay | 0:4e0085011ee0 | 76 | |
maria_launay | 0:4e0085011ee0 | 77 | //Détection de CO |
maria_launay | 0:4e0085011ee0 | 78 | if(bouton == 1){ |
maria_launay | 0:4e0085011ee0 | 79 | sprintf(str, "Recherche de CO"); |
maria_launay | 0:4e0085011ee0 | 80 | if(broche1 > 0.6){ |
maria_launay | 0:4e0085011ee0 | 81 | sprintf(broche, "Presence de CO "); |
maria_launay | 0:4e0085011ee0 | 82 | sprintf(attention, "attention"); |
maria_launay | 0:4e0085011ee0 | 83 | lcd.SetTextColor(LCD_COLOR_RED); |
maria_launay | 0:4e0085011ee0 | 84 | } |
maria_launay | 0:4e0085011ee0 | 85 | else { |
maria_launay | 0:4e0085011ee0 | 86 | sprintf(broche, "L'air ne contient pas de CO "); |
maria_launay | 0:4e0085011ee0 | 87 | sprintf(attention, " "); |
maria_launay | 0:4e0085011ee0 | 88 | lcd.SetTextColor(LCD_COLOR_WHITE); |
maria_launay | 0:4e0085011ee0 | 89 | } |
maria_launay | 0:4e0085011ee0 | 90 | } |
maria_launay | 0:4e0085011ee0 | 91 | |
maria_launay | 0:4e0085011ee0 | 92 | //Détection du Méthane |
maria_launay | 0:4e0085011ee0 | 93 | if(bouton == 2){ |
maria_launay | 0:4e0085011ee0 | 94 | sprintf(str, "Recherche de Methane"); |
maria_launay | 0:4e0085011ee0 | 95 | if(broche2 > 0.6){ |
maria_launay | 0:4e0085011ee0 | 96 | sprintf(broche, "Presence de Methane "); |
maria_launay | 0:4e0085011ee0 | 97 | sprintf(attention, "attention"); |
maria_launay | 0:4e0085011ee0 | 98 | lcd.SetTextColor(LCD_COLOR_RED); |
maria_launay | 0:4e0085011ee0 | 99 | } |
maria_launay | 0:4e0085011ee0 | 100 | else { |
maria_launay | 0:4e0085011ee0 | 101 | sprintf(broche, "L'air ne contient pas Methane "); |
maria_launay | 0:4e0085011ee0 | 102 | sprintf(attention, " "); |
maria_launay | 0:4e0085011ee0 | 103 | lcd.SetTextColor(LCD_COLOR_WHITE); |
maria_launay | 0:4e0085011ee0 | 104 | } |
maria_launay | 0:4e0085011ee0 | 105 | } |
maria_launay | 0:4e0085011ee0 | 106 | |
maria_launay | 0:4e0085011ee0 | 107 | //Détection de CO et de Méthane |
maria_launay | 0:4e0085011ee0 | 108 | if(bouton == 3){ |
maria_launay | 0:4e0085011ee0 | 109 | sprintf(str, "Recherche de CO et Methane"); |
maria_launay | 0:4e0085011ee0 | 110 | if((broche1 > 0.6) && (broche2 > 0.6)){ |
maria_launay | 0:4e0085011ee0 | 111 | sprintf(broche, "Presence de Methane et de CO "); |
maria_launay | 0:4e0085011ee0 | 112 | sprintf(attention, "attention"); |
maria_launay | 0:4e0085011ee0 | 113 | lcd.SetTextColor(LCD_COLOR_RED); |
maria_launay | 0:4e0085011ee0 | 114 | } |
maria_launay | 0:4e0085011ee0 | 115 | else if((broche1 > 0.6) && (broche2 < 0.6)){ |
maria_launay | 0:4e0085011ee0 | 116 | sprintf(broche, "Presence de CO mais pas de Methane "); |
maria_launay | 0:4e0085011ee0 | 117 | sprintf(attention, "attention"); |
maria_launay | 0:4e0085011ee0 | 118 | lcd.SetTextColor(LCD_COLOR_RED); |
maria_launay | 0:4e0085011ee0 | 119 | } |
maria_launay | 0:4e0085011ee0 | 120 | else if((broche1 < 0.6) && (broche2 > 0.6)){ |
maria_launay | 0:4e0085011ee0 | 121 | sprintf(broche, "Presence de Methane mais pas de CO "); |
maria_launay | 0:4e0085011ee0 | 122 | sprintf(attention, "attention"); |
maria_launay | 0:4e0085011ee0 | 123 | lcd.SetTextColor(LCD_COLOR_RED); |
maria_launay | 0:4e0085011ee0 | 124 | } |
maria_launay | 0:4e0085011ee0 | 125 | else { |
maria_launay | 0:4e0085011ee0 | 126 | sprintf(broche, "L'air ne contient pas de CO et de Methane"); |
maria_launay | 0:4e0085011ee0 | 127 | sprintf(attention, " "); |
maria_launay | 0:4e0085011ee0 | 128 | lcd.SetTextColor(LCD_COLOR_WHITE); |
maria_launay | 0:4e0085011ee0 | 129 | } |
maria_launay | 0:4e0085011ee0 | 130 | } |
maria_launay | 0:4e0085011ee0 | 131 | |
maria_launay | 0:4e0085011ee0 | 132 | } |
maria_launay | 0:4e0085011ee0 | 133 | } |