avec fonctions
Dependencies: DHT22 SSD1306 TCS34725 mbed
Fork of ProjetLong_Serre_V2 by
main.cpp@1:6a83787ddf2d, 2018-10-07 (annotated)
- Committer:
- leandre
- Date:
- Sun Oct 07 16:03:15 2018 +0000
- Revision:
- 1:6a83787ddf2d
- Parent:
- 0:3c21f316aef8
Version avec Ecran,DHT22 et premi?re impl?mentation du Moisture Sensor, RGB comment?
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
leandre | 0:3c21f316aef8 | 1 | #include "mbed.h" |
leandre | 0:3c21f316aef8 | 2 | #include "ssd1306.h" |
leandre | 0:3c21f316aef8 | 3 | #include "standard_font.h" |
leandre | 0:3c21f316aef8 | 4 | #include "bold_font.h" |
leandre | 0:3c21f316aef8 | 5 | #include "DHT22.h" |
leandre | 1:6a83787ddf2d | 6 | #include "Adafruit_TCS34725.h" |
leandre | 0:3c21f316aef8 | 7 | |
leandre | 1:6a83787ddf2d | 8 | //DEFINES |
leandre | 1:6a83787ddf2d | 9 | #define commonAnode true |
leandre | 1:6a83787ddf2d | 10 | |
leandre | 1:6a83787ddf2d | 11 | void initRGB(int TCS); |
leandre | 1:6a83787ddf2d | 12 | void GestionRGB(); |
leandre | 1:6a83787ddf2d | 13 | |
leandre | 1:6a83787ddf2d | 14 | int r,g,b; |
leandre | 0:3c21f316aef8 | 15 | |
leandre | 1:6a83787ddf2d | 16 | SSD1306 oled(D9,D6,D10,A4,A6); // OLED : CS,Reset,DC,Clock,Data (SPI1) |
leandre | 1:6a83787ddf2d | 17 | //I2C i2c(D4,D5);//SDA SCL |
leandre | 1:6a83787ddf2d | 18 | //DigitalOut myled(LED1);//ATTENTION LED1 = D13 |
leandre | 0:3c21f316aef8 | 19 | DHT22 dht22(D4); |
leandre | 1:6a83787ddf2d | 20 | Serial pc(USBTX, USBRX); |
leandre | 1:6a83787ddf2d | 21 | //Adafruit_TCS34725 tcs = Adafruit_TCS34725(&i2c, TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_4X); |
leandre | 1:6a83787ddf2d | 22 | |
leandre | 1:6a83787ddf2d | 23 | AnalogIn sondeHum(A0); |
leandre | 1:6a83787ddf2d | 24 | AnalogIn sondeTemp(A1); |
leandre | 1:6a83787ddf2d | 25 | |
leandre | 0:3c21f316aef8 | 26 | |
leandre | 0:3c21f316aef8 | 27 | int main() { |
leandre | 0:3c21f316aef8 | 28 | |
leandre | 1:6a83787ddf2d | 29 | pc.printf("\n\r\tProjet SERRE : \n\r"); |
leandre | 1:6a83787ddf2d | 30 | pc.printf("\n\r\tCURIEL DKHEILA FURA\n\r\n\r"); |
leandre | 1:6a83787ddf2d | 31 | |
leandre | 1:6a83787ddf2d | 32 | float humAir=12.12;//Valeur d'init pour verifier pannes |
leandre | 1:6a83787ddf2d | 33 | float tempAir=13.13; |
leandre | 1:6a83787ddf2d | 34 | |
leandre | 1:6a83787ddf2d | 35 | float humSol=13.13;//Valeur d'init pour verifier pannes |
leandre | 1:6a83787ddf2d | 36 | float tempSol=13.13; |
leandre | 0:3c21f316aef8 | 37 | |
leandre | 0:3c21f316aef8 | 38 | oled.initialise(); |
leandre | 0:3c21f316aef8 | 39 | oled.clear(); |
leandre | 0:3c21f316aef8 | 40 | oled.set_contrast(255); // max contrast |
leandre | 0:3c21f316aef8 | 41 | oled.update(); |
leandre | 0:3c21f316aef8 | 42 | |
leandre | 1:6a83787ddf2d | 43 | oled.clear(); |
leandre | 1:6a83787ddf2d | 44 | oled.set_font(bold_font, 8); |
leandre | 1:6a83787ddf2d | 45 | oled.printf("Demarrage...\r\n"); |
leandre | 1:6a83787ddf2d | 46 | oled.update(); |
leandre | 1:6a83787ddf2d | 47 | |
leandre | 1:6a83787ddf2d | 48 | //initRGB(tcs.begin()); |
leandre | 1:6a83787ddf2d | 49 | wait(2.0); |
leandre | 1:6a83787ddf2d | 50 | oled.printf("OK\r\n"); |
leandre | 1:6a83787ddf2d | 51 | oled.update(); |
leandre | 1:6a83787ddf2d | 52 | |
leandre | 1:6a83787ddf2d | 53 | |
leandre | 0:3c21f316aef8 | 54 | while(1) { |
leandre | 0:3c21f316aef8 | 55 | |
leandre | 0:3c21f316aef8 | 56 | |
leandre | 0:3c21f316aef8 | 57 | wait(1.0); // 1 sec |
leandre | 0:3c21f316aef8 | 58 | |
leandre | 1:6a83787ddf2d | 59 | //HUM/TEMP AIR |
leandre | 0:3c21f316aef8 | 60 | dht22.sample() ; |
leandre | 1:6a83787ddf2d | 61 | humAir=dht22.getHumidity()/10.0; |
leandre | 1:6a83787ddf2d | 62 | tempAir=dht22.getTemperature()/10.0; |
leandre | 1:6a83787ddf2d | 63 | |
leandre | 1:6a83787ddf2d | 64 | //TEMP SOL |
leandre | 1:6a83787ddf2d | 65 | |
leandre | 1:6a83787ddf2d | 66 | //AFFICHAGE |
leandre | 1:6a83787ddf2d | 67 | oled.clear(); |
leandre | 1:6a83787ddf2d | 68 | |
leandre | 1:6a83787ddf2d | 69 | //AIR |
leandre | 1:6a83787ddf2d | 70 | oled.set_font(bold_font, 8); |
leandre | 1:6a83787ddf2d | 71 | oled.printf("AIR\r\n"); |
leandre | 1:6a83787ddf2d | 72 | oled.set_font(standard_font, 6); |
leandre | 1:6a83787ddf2d | 73 | oled.printf("Humidite: %.2f %%\r\n", humAir); |
leandre | 1:6a83787ddf2d | 74 | oled.printf("Temperature: %.2f C\r\n", tempAir); |
leandre | 1:6a83787ddf2d | 75 | |
leandre | 1:6a83787ddf2d | 76 | pc.printf("AIR\r\n"); |
leandre | 1:6a83787ddf2d | 77 | pc.printf("Humidite: %.2f %%\r\n", humAir); |
leandre | 1:6a83787ddf2d | 78 | pc.printf("Temperature: %.2f C\r\n\r\n", tempAir); |
leandre | 1:6a83787ddf2d | 79 | |
leandre | 1:6a83787ddf2d | 80 | //SOL |
leandre | 1:6a83787ddf2d | 81 | //tempSol=sondeTemp; //A MODIFIER!!!!! |
leandre | 1:6a83787ddf2d | 82 | humSol=sondeHum;//A MODIFIER !!!!! |
leandre | 1:6a83787ddf2d | 83 | oled.set_font(bold_font, 8); |
leandre | 1:6a83787ddf2d | 84 | oled.printf("SOL\r\n"); |
leandre | 1:6a83787ddf2d | 85 | oled.set_font(standard_font, 6); |
leandre | 1:6a83787ddf2d | 86 | oled.printf("Humidite %.2f %\r\n", humSol); |
leandre | 1:6a83787ddf2d | 87 | //oled.printf("Temperature %.2f C\r\n", tempSol); |
leandre | 0:3c21f316aef8 | 88 | |
leandre | 0:3c21f316aef8 | 89 | |
leandre | 1:6a83787ddf2d | 90 | pc.printf("SOL\n\f"); |
leandre | 1:6a83787ddf2d | 91 | pc.printf("Humidite: %.2f %%\r\n", humSol); |
leandre | 1:6a83787ddf2d | 92 | //pc.printf("Temperature: %.2f C\r\n", tempSol); */ |
leandre | 1:6a83787ddf2d | 93 | |
leandre | 1:6a83787ddf2d | 94 | //LUMINOSITE*/ |
leandre | 1:6a83787ddf2d | 95 | |
leandre | 1:6a83787ddf2d | 96 | //RGB |
leandre | 1:6a83787ddf2d | 97 | //GestionRGB(); |
leandre | 1:6a83787ddf2d | 98 | |
leandre | 1:6a83787ddf2d | 99 | |
leandre | 0:3c21f316aef8 | 100 | oled.update(); |
leandre | 0:3c21f316aef8 | 101 | |
leandre | 1:6a83787ddf2d | 102 | |
leandre | 1:6a83787ddf2d | 103 | //printf("temp: %.2f C , hum:%.2f %% \n\r",temp,hum); |
leandre | 0:3c21f316aef8 | 104 | |
leandre | 0:3c21f316aef8 | 105 | } |
leandre | 0:3c21f316aef8 | 106 | } |
leandre | 0:3c21f316aef8 | 107 | |
leandre | 1:6a83787ddf2d | 108 | void initRGB(int TCS) |
leandre | 1:6a83787ddf2d | 109 | { |
leandre | 1:6a83787ddf2d | 110 | //---INIT RGB--- |
leandre | 1:6a83787ddf2d | 111 | char gammatable[256]; |
leandre | 1:6a83787ddf2d | 112 | if (TCS) |
leandre | 1:6a83787ddf2d | 113 | { |
leandre | 1:6a83787ddf2d | 114 | pc.printf("Found sensor"); |
leandre | 1:6a83787ddf2d | 115 | } |
leandre | 1:6a83787ddf2d | 116 | else |
leandre | 1:6a83787ddf2d | 117 | { |
leandre | 1:6a83787ddf2d | 118 | pc.printf("No TCS34725 found ... check your connections"); |
leandre | 1:6a83787ddf2d | 119 | while (1); // halt! |
leandre | 1:6a83787ddf2d | 120 | } |
leandre | 1:6a83787ddf2d | 121 | for (int i=0; i<256; i++) |
leandre | 1:6a83787ddf2d | 122 | { |
leandre | 1:6a83787ddf2d | 123 | float x = i; |
leandre | 1:6a83787ddf2d | 124 | x /= 255; |
leandre | 1:6a83787ddf2d | 125 | x = pow((double)x, 2.5); |
leandre | 1:6a83787ddf2d | 126 | x *= 255; |
leandre | 1:6a83787ddf2d | 127 | if (commonAnode) |
leandre | 1:6a83787ddf2d | 128 | { |
leandre | 1:6a83787ddf2d | 129 | gammatable[i] = 255 - x; |
leandre | 1:6a83787ddf2d | 130 | } |
leandre | 1:6a83787ddf2d | 131 | else |
leandre | 1:6a83787ddf2d | 132 | { |
leandre | 1:6a83787ddf2d | 133 | gammatable[i] = x; |
leandre | 1:6a83787ddf2d | 134 | } |
leandre | 1:6a83787ddf2d | 135 | //printf("%d\r\n", gammatable[i]); |
leandre | 1:6a83787ddf2d | 136 | } |
leandre | 1:6a83787ddf2d | 137 | //---FIN INIT RGB--- |
leandre | 1:6a83787ddf2d | 138 | } |
leandre | 0:3c21f316aef8 | 139 | |
leandre | 1:6a83787ddf2d | 140 | |
leandre | 1:6a83787ddf2d | 141 | /*void GestionRGB() |
leandre | 1:6a83787ddf2d | 142 | { |
leandre | 1:6a83787ddf2d | 143 | uint16_t clear, red, green, blue; |
leandre | 1:6a83787ddf2d | 144 | tcs.setInterrupt(false); // turn on LED |
leandre | 1:6a83787ddf2d | 145 | tcs.getRawData(&red, &green, &blue, &clear); |
leandre | 1:6a83787ddf2d | 146 | tcs.setInterrupt(true); // turn off LED |
leandre | 1:6a83787ddf2d | 147 | //printf("%d, %d, %d, %d\r\n", clear, red, green, blue); |
leandre | 1:6a83787ddf2d | 148 | // Figure out some basic hex code for visualization |
leandre | 1:6a83787ddf2d | 149 | uint32_t sum = clear; |
leandre | 1:6a83787ddf2d | 150 | r = red; r /= sum; |
leandre | 1:6a83787ddf2d | 151 | g = green; g /= sum; |
leandre | 1:6a83787ddf2d | 152 | b = blue; b /= sum; |
leandre | 1:6a83787ddf2d | 153 | r *= 256; g *= 256; b *= 256; |
leandre | 1:6a83787ddf2d | 154 | pc.printf("R : %d, G : %d, B : %d\r\n", r, g, b); |
leandre | 1:6a83787ddf2d | 155 | wait(2); |
leandre | 1:6a83787ddf2d | 156 | }*/ |