avec fonctions
Dependencies: DHT22 SSD1306 TCS34725 mbed
Fork of ProjetLong_Serre_V3 by
main.cpp@0:3c21f316aef8, 2018-09-18 (annotated)
- Committer:
- leandre
- Date:
- Tue Sep 18 10:29:52 2018 +0000
- Revision:
- 0:3c21f316aef8
- Child:
- 1:6a83787ddf2d
b
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 | 0:3c21f316aef8 | 6 | |
leandre | 0:3c21f316aef8 | 7 | |
leandre | 0:3c21f316aef8 | 8 | SSD1306 oled(PB_0,PB_4,PB_5,PA_5,PA_7); // OLED : CS,Reset,DC,Clock,Data |
leandre | 0:3c21f316aef8 | 9 | I2C i2c(PB_7,PB_6); |
leandre | 0:3c21f316aef8 | 10 | DigitalOut myled(LED1); |
leandre | 0:3c21f316aef8 | 11 | DHT22 dht22(D4); |
leandre | 0:3c21f316aef8 | 12 | |
leandre | 0:3c21f316aef8 | 13 | int main() { |
leandre | 0:3c21f316aef8 | 14 | |
leandre | 0:3c21f316aef8 | 15 | float hum; |
leandre | 0:3c21f316aef8 | 16 | float temp; |
leandre | 0:3c21f316aef8 | 17 | |
leandre | 0:3c21f316aef8 | 18 | oled.initialise(); |
leandre | 0:3c21f316aef8 | 19 | oled.clear(); |
leandre | 0:3c21f316aef8 | 20 | oled.set_contrast(255); // max contrast |
leandre | 0:3c21f316aef8 | 21 | oled.update(); |
leandre | 0:3c21f316aef8 | 22 | |
leandre | 0:3c21f316aef8 | 23 | while(1) { |
leandre | 0:3c21f316aef8 | 24 | |
leandre | 0:3c21f316aef8 | 25 | |
leandre | 0:3c21f316aef8 | 26 | wait(1.0); // 1 sec |
leandre | 0:3c21f316aef8 | 27 | |
leandre | 0:3c21f316aef8 | 28 | dht22.sample() ; |
leandre | 0:3c21f316aef8 | 29 | hum=dht22.getHumidity()/10.0; |
leandre | 0:3c21f316aef8 | 30 | temp=dht22.getTemperature()/10.0; |
leandre | 0:3c21f316aef8 | 31 | |
leandre | 0:3c21f316aef8 | 32 | |
leandre | 0:3c21f316aef8 | 33 | oled.clear(); |
leandre | 0:3c21f316aef8 | 34 | oled.set_font(bold_font, 8); |
leandre | 0:3c21f316aef8 | 35 | oled.printf("DHT22\r\n"); |
leandre | 0:3c21f316aef8 | 36 | oled.printf("\r\n"); |
leandre | 0:3c21f316aef8 | 37 | oled.set_font(standard_font, 6); |
leandre | 0:3c21f316aef8 | 38 | oled.printf("Humidite: %.2f %%\r\n", hum); |
leandre | 0:3c21f316aef8 | 39 | oled.printf("Temperature: %.2f C\r\n", temp); |
leandre | 0:3c21f316aef8 | 40 | oled.printf("\r\n"); |
leandre | 0:3c21f316aef8 | 41 | oled.update(); |
leandre | 0:3c21f316aef8 | 42 | |
leandre | 0:3c21f316aef8 | 43 | printf("temp: %.2f C , hum:%.2f %% \n\r",temp,hum); |
leandre | 0:3c21f316aef8 | 44 | |
leandre | 0:3c21f316aef8 | 45 | } |
leandre | 0:3c21f316aef8 | 46 | } |
leandre | 0:3c21f316aef8 | 47 | |
leandre | 0:3c21f316aef8 | 48 |