avec fonctions
Dependencies: DHT22 SSD1306 TCS34725 mbed
Fork of ProjetLong_Serre_V3 by
Diff: main.cpp
- Revision:
- 1:6a83787ddf2d
- Parent:
- 0:3c21f316aef8
diff -r 3c21f316aef8 -r 6a83787ddf2d main.cpp --- a/main.cpp Tue Sep 18 10:29:52 2018 +0000 +++ b/main.cpp Sun Oct 07 16:03:15 2018 +0000 @@ -3,46 +3,154 @@ #include "standard_font.h" #include "bold_font.h" #include "DHT22.h" +#include "Adafruit_TCS34725.h" +//DEFINES +#define commonAnode true + +void initRGB(int TCS); +void GestionRGB(); + +int r,g,b; -SSD1306 oled(PB_0,PB_4,PB_5,PA_5,PA_7); // OLED : CS,Reset,DC,Clock,Data -I2C i2c(PB_7,PB_6); -DigitalOut myled(LED1); +SSD1306 oled(D9,D6,D10,A4,A6); // OLED : CS,Reset,DC,Clock,Data (SPI1) +//I2C i2c(D4,D5);//SDA SCL +//DigitalOut myled(LED1);//ATTENTION LED1 = D13 DHT22 dht22(D4); +Serial pc(USBTX, USBRX); +//Adafruit_TCS34725 tcs = Adafruit_TCS34725(&i2c, TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_4X); + +AnalogIn sondeHum(A0); +AnalogIn sondeTemp(A1); + int main() { - float hum; - float temp; + pc.printf("\n\r\tProjet SERRE : \n\r"); + pc.printf("\n\r\tCURIEL DKHEILA FURA\n\r\n\r"); + + float humAir=12.12;//Valeur d'init pour verifier pannes + float tempAir=13.13; + + float humSol=13.13;//Valeur d'init pour verifier pannes + float tempSol=13.13; oled.initialise(); oled.clear(); oled.set_contrast(255); // max contrast oled.update(); + oled.clear(); + oled.set_font(bold_font, 8); + oled.printf("Demarrage...\r\n"); + oled.update(); + + //initRGB(tcs.begin()); + wait(2.0); + oled.printf("OK\r\n"); + oled.update(); + + while(1) { wait(1.0); // 1 sec + //HUM/TEMP AIR dht22.sample() ; - hum=dht22.getHumidity()/10.0; - temp=dht22.getTemperature()/10.0; + humAir=dht22.getHumidity()/10.0; + tempAir=dht22.getTemperature()/10.0; + + //TEMP SOL + + //AFFICHAGE + oled.clear(); + + //AIR + oled.set_font(bold_font, 8); + oled.printf("AIR\r\n"); + oled.set_font(standard_font, 6); + oled.printf("Humidite: %.2f %%\r\n", humAir); + oled.printf("Temperature: %.2f C\r\n", tempAir); + + pc.printf("AIR\r\n"); + pc.printf("Humidite: %.2f %%\r\n", humAir); + pc.printf("Temperature: %.2f C\r\n\r\n", tempAir); + + //SOL + //tempSol=sondeTemp; //A MODIFIER!!!!! + humSol=sondeHum;//A MODIFIER !!!!! + oled.set_font(bold_font, 8); + oled.printf("SOL\r\n"); + oled.set_font(standard_font, 6); + oled.printf("Humidite %.2f %\r\n", humSol); + //oled.printf("Temperature %.2f C\r\n", tempSol); - oled.clear(); - oled.set_font(bold_font, 8); - oled.printf("DHT22\r\n"); - oled.printf("\r\n"); - oled.set_font(standard_font, 6); - oled.printf("Humidite: %.2f %%\r\n", hum); - oled.printf("Temperature: %.2f C\r\n", temp); - oled.printf("\r\n"); + pc.printf("SOL\n\f"); + pc.printf("Humidite: %.2f %%\r\n", humSol); + //pc.printf("Temperature: %.2f C\r\n", tempSol); */ + + //LUMINOSITE*/ + + //RGB + //GestionRGB(); + + oled.update(); - printf("temp: %.2f C , hum:%.2f %% \n\r",temp,hum); + + //printf("temp: %.2f C , hum:%.2f %% \n\r",temp,hum); } } +void initRGB(int TCS) +{ + //---INIT RGB--- + char gammatable[256]; + if (TCS) + { + pc.printf("Found sensor"); + } + else + { + pc.printf("No TCS34725 found ... check your connections"); + while (1); // halt! + } + for (int i=0; i<256; i++) + { + float x = i; + x /= 255; + x = pow((double)x, 2.5); + x *= 255; + if (commonAnode) + { + gammatable[i] = 255 - x; + } + else + { + gammatable[i] = x; + } + //printf("%d\r\n", gammatable[i]); + } + //---FIN INIT RGB--- +} + +/*void GestionRGB() +{ + uint16_t clear, red, green, blue; + tcs.setInterrupt(false); // turn on LED + tcs.getRawData(&red, &green, &blue, &clear); + tcs.setInterrupt(true); // turn off LED + //printf("%d, %d, %d, %d\r\n", clear, red, green, blue); + // Figure out some basic hex code for visualization + uint32_t sum = clear; + r = red; r /= sum; + g = green; g /= sum; + b = blue; b /= sum; + r *= 256; g *= 256; b *= 256; + pc.printf("R : %d, G : %d, B : %d\r\n", r, g, b); + wait(2); +}*/ \ No newline at end of file