avec fonctions
Dependencies: DHT22 SSD1306 TCS34725 mbed
Fork of ProjetLong_Serre_V3 by
ProjetLong_Main.cpp@2:4cf39fcca3f3, 2018-10-15 (annotated)
- Committer:
- leandre
- Date:
- Mon Oct 15 12:31:22 2018 +0000
- Revision:
- 2:4cf39fcca3f3
- Parent:
- main.cpp@1:6a83787ddf2d
pouf
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
leandre | 2:4cf39fcca3f3 | 1 | /*-- BIBLIOTHEQUES --*/ |
leandre | 0:3c21f316aef8 | 2 | #include "mbed.h" |
leandre | 0:3c21f316aef8 | 3 | #include "ssd1306.h" |
leandre | 0:3c21f316aef8 | 4 | #include "standard_font.h" |
leandre | 0:3c21f316aef8 | 5 | #include "bold_font.h" |
leandre | 0:3c21f316aef8 | 6 | #include "DHT22.h" |
leandre | 1:6a83787ddf2d | 7 | #include "Adafruit_TCS34725.h" |
leandre | 2:4cf39fcca3f3 | 8 | /*-------------------*/ |
leandre | 0:3c21f316aef8 | 9 | |
leandre | 2:4cf39fcca3f3 | 10 | /*-- DEFINES --*/ |
leandre | 1:6a83787ddf2d | 11 | #define commonAnode true |
leandre | 1:6a83787ddf2d | 12 | |
leandre | 2:4cf39fcca3f3 | 13 | #define ERR_RGB 0 |
leandre | 2:4cf39fcca3f3 | 14 | /*----------------------*/ |
leandre | 2:4cf39fcca3f3 | 15 | |
leandre | 2:4cf39fcca3f3 | 16 | |
leandre | 2:4cf39fcca3f3 | 17 | /*-- PROTOTYPES --*/ |
leandre | 2:4cf39fcca3f3 | 18 | void GetDataAir(void); |
leandre | 2:4cf39fcca3f3 | 19 | void InitEcran(void); |
leandre | 2:4cf39fcca3f3 | 20 | void GestionEcran(void); |
leandre | 2:4cf39fcca3f3 | 21 | void ErrorDisplay(int ErrorNumber); |
leandre | 2:4cf39fcca3f3 | 22 | void initRGB(); |
leandre | 1:6a83787ddf2d | 23 | void GestionRGB(); |
leandre | 2:4cf39fcca3f3 | 24 | /*-----------------------*/ |
leandre | 2:4cf39fcca3f3 | 25 | |
leandre | 2:4cf39fcca3f3 | 26 | |
leandre | 2:4cf39fcca3f3 | 27 | /*-- PERIPHERIQUES --*/ |
leandre | 2:4cf39fcca3f3 | 28 | SSD1306 oled(D9,D6,D10,A4,A6); // OLED : CS,Reset,DC,Clock,Data (SPI1) |
leandre | 2:4cf39fcca3f3 | 29 | I2C i2c(D4,D5);//SDA SCL |
leandre | 2:4cf39fcca3f3 | 30 | //DigitalOut myled(LED1);//ATTENTION LED1 = D13 |
leandre | 2:4cf39fcca3f3 | 31 | DHT22 dht22(D3); //Capteur Temperature AIR |
leandre | 2:4cf39fcca3f3 | 32 | Serial pc(USBTX, USBRX); |
leandre | 2:4cf39fcca3f3 | 33 | Adafruit_TCS34725 tcs = Adafruit_TCS34725(&i2c, TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_4X); //RGB Sensor |
leandre | 2:4cf39fcca3f3 | 34 | DigitalOut LedTCS(D11); |
leandre | 2:4cf39fcca3f3 | 35 | |
leandre | 2:4cf39fcca3f3 | 36 | AnalogIn sondeHum(A0); //Capteur Humidite SOL |
leandre | 2:4cf39fcca3f3 | 37 | AnalogIn sondeTemp(A1); //Capteur Temperature SOL |
leandre | 2:4cf39fcca3f3 | 38 | /*--------------------*/ |
leandre | 2:4cf39fcca3f3 | 39 | |
leandre | 2:4cf39fcca3f3 | 40 | |
leandre | 2:4cf39fcca3f3 | 41 | /*-- VARIABLES GLOBALES --*/ |
leandre | 2:4cf39fcca3f3 | 42 | float humAir=12.12;//Valeur d'init pour verifier pannes |
leandre | 2:4cf39fcca3f3 | 43 | float tempAir=13.13; |
leandre | 2:4cf39fcca3f3 | 44 | |
leandre | 2:4cf39fcca3f3 | 45 | float humSol=14.14;//Valeur d'init pour verifier pannes |
leandre | 2:4cf39fcca3f3 | 46 | float tempSol=15.15; |
leandre | 1:6a83787ddf2d | 47 | |
leandre | 1:6a83787ddf2d | 48 | int r,g,b; |
leandre | 2:4cf39fcca3f3 | 49 | /*-----------------------*/ |
leandre | 0:3c21f316aef8 | 50 | |
leandre | 0:3c21f316aef8 | 51 | int main() { |
leandre | 0:3c21f316aef8 | 52 | |
leandre | 1:6a83787ddf2d | 53 | pc.printf("\n\r\tProjet SERRE : \n\r"); |
leandre | 1:6a83787ddf2d | 54 | pc.printf("\n\r\tCURIEL DKHEILA FURA\n\r\n\r"); |
leandre | 2:4cf39fcca3f3 | 55 | |
leandre | 2:4cf39fcca3f3 | 56 | initRGB(); |
leandre | 2:4cf39fcca3f3 | 57 | |
leandre | 2:4cf39fcca3f3 | 58 | InitEcran(); |
leandre | 1:6a83787ddf2d | 59 | |
leandre | 2:4cf39fcca3f3 | 60 | while(1) { |
leandre | 2:4cf39fcca3f3 | 61 | |
leandre | 2:4cf39fcca3f3 | 62 | wait(1.0); // 1 sec |
leandre | 2:4cf39fcca3f3 | 63 | |
leandre | 2:4cf39fcca3f3 | 64 | /*-- Humidite & Temperature AIR --*/ |
leandre | 2:4cf39fcca3f3 | 65 | GetDataAir(); |
leandre | 2:4cf39fcca3f3 | 66 | |
leandre | 2:4cf39fcca3f3 | 67 | /*-- Humidite & Temperature SOL --*/ |
leandre | 2:4cf39fcca3f3 | 68 | humSol=sondeHum;//A MODIFIER !!!!! |
leandre | 2:4cf39fcca3f3 | 69 | //tempSol=sondeTemp; //A MODIFIER!!!!! |
leandre | 2:4cf39fcca3f3 | 70 | pc.printf("SOL\n\f"); |
leandre | 2:4cf39fcca3f3 | 71 | pc.printf("Humidite: %.2f %%\r\n", humSol); |
leandre | 2:4cf39fcca3f3 | 72 | //pc.printf("Temperature: %.2f C\r\n\r\n", tempSol); */ |
leandre | 2:4cf39fcca3f3 | 73 | |
leandre | 2:4cf39fcca3f3 | 74 | /*-- LUMIERE --*/ |
leandre | 2:4cf39fcca3f3 | 75 | |
leandre | 2:4cf39fcca3f3 | 76 | /*__ RGB __*/ |
leandre | 2:4cf39fcca3f3 | 77 | //GestionRGB(); |
leandre | 2:4cf39fcca3f3 | 78 | |
leandre | 2:4cf39fcca3f3 | 79 | /*__ Spectre visible et infrarouge __*/ |
leandre | 2:4cf39fcca3f3 | 80 | |
leandre | 2:4cf39fcca3f3 | 81 | /*-- AFFICHAGE --*/ |
leandre | 2:4cf39fcca3f3 | 82 | GestionEcran(); |
leandre | 2:4cf39fcca3f3 | 83 | } |
leandre | 2:4cf39fcca3f3 | 84 | } |
leandre | 2:4cf39fcca3f3 | 85 | |
leandre | 2:4cf39fcca3f3 | 86 | //Lecture de l'humidite et de la temperature de l'air |
leandre | 2:4cf39fcca3f3 | 87 | void GetDataAir(void) |
leandre | 2:4cf39fcca3f3 | 88 | { |
leandre | 2:4cf39fcca3f3 | 89 | dht22.sample() ; |
leandre | 2:4cf39fcca3f3 | 90 | humAir=dht22.getHumidity()/10.0; |
leandre | 2:4cf39fcca3f3 | 91 | tempAir=dht22.getTemperature()/10.0; |
leandre | 0:3c21f316aef8 | 92 | |
leandre | 2:4cf39fcca3f3 | 93 | pc.printf("AIR\r\n"); |
leandre | 2:4cf39fcca3f3 | 94 | pc.printf("Humidite: %.2f %%\r\n", humAir); |
leandre | 2:4cf39fcca3f3 | 95 | pc.printf("Temperature: %.2f C\r\n\r\n", tempAir); |
leandre | 2:4cf39fcca3f3 | 96 | } |
leandre | 2:4cf39fcca3f3 | 97 | |
leandre | 2:4cf39fcca3f3 | 98 | //Initialisation de l'ecran |
leandre | 2:4cf39fcca3f3 | 99 | void InitEcran(void) |
leandre | 2:4cf39fcca3f3 | 100 | { |
leandre | 0:3c21f316aef8 | 101 | oled.initialise(); |
leandre | 0:3c21f316aef8 | 102 | oled.clear(); |
leandre | 0:3c21f316aef8 | 103 | oled.set_contrast(255); // max contrast |
leandre | 0:3c21f316aef8 | 104 | oled.update(); |
leandre | 0:3c21f316aef8 | 105 | |
leandre | 1:6a83787ddf2d | 106 | oled.clear(); |
leandre | 1:6a83787ddf2d | 107 | oled.set_font(bold_font, 8); |
leandre | 2:4cf39fcca3f3 | 108 | oled.printf("Bienvenue\n\ra Jurassic Park\r\n"); |
leandre | 1:6a83787ddf2d | 109 | oled.update(); |
leandre | 1:6a83787ddf2d | 110 | |
leandre | 2:4cf39fcca3f3 | 111 | wait(1); |
leandre | 0:3c21f316aef8 | 112 | } |
leandre | 0:3c21f316aef8 | 113 | |
leandre | 2:4cf39fcca3f3 | 114 | //Affichage des donnees utiles sur l'ecran |
leandre | 2:4cf39fcca3f3 | 115 | void GestionEcran(void) |
leandre | 1:6a83787ddf2d | 116 | { |
leandre | 2:4cf39fcca3f3 | 117 | oled.clear(); |
leandre | 2:4cf39fcca3f3 | 118 | |
leandre | 2:4cf39fcca3f3 | 119 | //AIR |
leandre | 2:4cf39fcca3f3 | 120 | oled.set_font(bold_font, 8); |
leandre | 2:4cf39fcca3f3 | 121 | oled.printf("AIR\r\n"); |
leandre | 2:4cf39fcca3f3 | 122 | oled.set_font(standard_font, 6); |
leandre | 2:4cf39fcca3f3 | 123 | oled.printf("Humidite: %.2f %%\r\n", humAir); |
leandre | 2:4cf39fcca3f3 | 124 | oled.printf("Temperature: %.2f C\r\n", tempAir); |
leandre | 2:4cf39fcca3f3 | 125 | |
leandre | 2:4cf39fcca3f3 | 126 | //SOL |
leandre | 2:4cf39fcca3f3 | 127 | oled.set_font(bold_font, 8); |
leandre | 2:4cf39fcca3f3 | 128 | oled.printf("SOL\r\n"); |
leandre | 2:4cf39fcca3f3 | 129 | oled.set_font(standard_font, 6); |
leandre | 2:4cf39fcca3f3 | 130 | oled.printf("Humidite %.2f %\r\n", humSol); |
leandre | 2:4cf39fcca3f3 | 131 | //oled.printf("Temperature %.2f C\r\n", tempSol); |
leandre | 2:4cf39fcca3f3 | 132 | |
leandre | 2:4cf39fcca3f3 | 133 | //RGB |
leandre | 2:4cf39fcca3f3 | 134 | oled.set_font(bold_font, 8); |
leandre | 2:4cf39fcca3f3 | 135 | oled.printf("Couleurs\r\n"); |
leandre | 2:4cf39fcca3f3 | 136 | oled.set_font(standard_font, 6); |
leandre | 2:4cf39fcca3f3 | 137 | oled.printf("R: %d, G: %d, B: %d\r\n",r, g, b); |
leandre | 2:4cf39fcca3f3 | 138 | |
leandre | 2:4cf39fcca3f3 | 139 | oled.update(); |
leandre | 2:4cf39fcca3f3 | 140 | } |
leandre | 2:4cf39fcca3f3 | 141 | |
leandre | 2:4cf39fcca3f3 | 142 | //Affichage de code erreur sur l'ecran |
leandre | 2:4cf39fcca3f3 | 143 | void ErrorDisplay(int ErrorNumber) |
leandre | 2:4cf39fcca3f3 | 144 | { |
leandre | 2:4cf39fcca3f3 | 145 | oled.clear(); |
leandre | 2:4cf39fcca3f3 | 146 | oled.set_font(bold_font, 8); |
leandre | 2:4cf39fcca3f3 | 147 | oled.printf("ERREUR : %d\r\n",ErrorNumber); |
leandre | 2:4cf39fcca3f3 | 148 | oled.update(); |
leandre | 2:4cf39fcca3f3 | 149 | pc.printf("ERREUR : %d\r\n",ErrorNumber); |
leandre | 2:4cf39fcca3f3 | 150 | wait(2); |
leandre | 2:4cf39fcca3f3 | 151 | } |
leandre | 2:4cf39fcca3f3 | 152 | |
leandre | 2:4cf39fcca3f3 | 153 | //Initialisation du capteur de couleurs RGB |
leandre | 2:4cf39fcca3f3 | 154 | void initRGB(void) |
leandre | 2:4cf39fcca3f3 | 155 | { |
leandre | 2:4cf39fcca3f3 | 156 | if (tcs.begin()) |
leandre | 1:6a83787ddf2d | 157 | { |
leandre | 1:6a83787ddf2d | 158 | pc.printf("Found sensor"); |
leandre | 2:4cf39fcca3f3 | 159 | LedTCS=1; |
leandre | 1:6a83787ddf2d | 160 | } |
leandre | 1:6a83787ddf2d | 161 | else |
leandre | 1:6a83787ddf2d | 162 | { |
leandre | 1:6a83787ddf2d | 163 | pc.printf("No TCS34725 found ... check your connections"); |
leandre | 2:4cf39fcca3f3 | 164 | ErrorDisplay(ERR_RGB); |
leandre | 1:6a83787ddf2d | 165 | while (1); // halt! |
leandre | 1:6a83787ddf2d | 166 | } |
leandre | 1:6a83787ddf2d | 167 | } |
leandre | 0:3c21f316aef8 | 168 | |
leandre | 2:4cf39fcca3f3 | 169 | //Acquisition des couleurs avec le capteur RGB |
leandre | 2:4cf39fcca3f3 | 170 | void GestionRGB(void) |
leandre | 1:6a83787ddf2d | 171 | { |
leandre | 1:6a83787ddf2d | 172 | uint16_t clear, red, green, blue; |
leandre | 2:4cf39fcca3f3 | 173 | |
leandre | 2:4cf39fcca3f3 | 174 | LedTCS=0; |
leandre | 2:4cf39fcca3f3 | 175 | wait(0.1); |
leandre | 2:4cf39fcca3f3 | 176 | |
leandre | 1:6a83787ddf2d | 177 | tcs.setInterrupt(false); // turn on LED |
leandre | 1:6a83787ddf2d | 178 | tcs.getRawData(&red, &green, &blue, &clear); |
leandre | 1:6a83787ddf2d | 179 | tcs.setInterrupt(true); // turn off LED |
leandre | 1:6a83787ddf2d | 180 | //printf("%d, %d, %d, %d\r\n", clear, red, green, blue); |
leandre | 2:4cf39fcca3f3 | 181 | |
leandre | 2:4cf39fcca3f3 | 182 | // Conversion Hexa |
leandre | 1:6a83787ddf2d | 183 | uint32_t sum = clear; |
leandre | 1:6a83787ddf2d | 184 | r = red; r /= sum; |
leandre | 1:6a83787ddf2d | 185 | g = green; g /= sum; |
leandre | 1:6a83787ddf2d | 186 | b = blue; b /= sum; |
leandre | 1:6a83787ddf2d | 187 | r *= 256; g *= 256; b *= 256; |
leandre | 2:4cf39fcca3f3 | 188 | pc.printf("R : %d, G : %d, B : %d\r\n", r, g, b); |
leandre | 2:4cf39fcca3f3 | 189 | |
leandre | 2:4cf39fcca3f3 | 190 | LedTCS=1; |
leandre | 2:4cf39fcca3f3 | 191 | } |