Programme de démonstration DHT11
Dependencies: DHT
main.cpp@1:61d800d62542, 2019-08-13 (annotated)
- Committer:
- bastienvincke
- Date:
- Tue Aug 13 08:09:44 2019 +0000
- Revision:
- 1:61d800d62542
- Parent:
- 0:97c2d4128ff3
V1 BV
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
david8251 | 0:97c2d4128ff3 | 1 | #include "mbed.h" |
bastienvincke | 1:61d800d62542 | 2 | #include "DHT.h" // on inclue la librairie |
david8251 | 0:97c2d4128ff3 | 3 | |
bastienvincke | 1:61d800d62542 | 4 | DigitalOut myled(LED1); // on utilisera la led embarqué sur la carte |
bastienvincke | 1:61d800d62542 | 5 | DHT dht11(PB_10,DHT11); // on déclare le capteur (connecté sur le port DIO_D6 de la carte L073RZ) |
david8251 | 0:97c2d4128ff3 | 6 | |
david8251 | 0:97c2d4128ff3 | 7 | int main() |
bastienvincke | 1:61d800d62542 | 8 | { |
bastienvincke | 1:61d800d62542 | 9 | int err; |
bastienvincke | 1:61d800d62542 | 10 | float temperature; |
bastienvincke | 1:61d800d62542 | 11 | float humidite; |
bastienvincke | 1:61d800d62542 | 12 | float point_rose; |
bastienvincke | 1:61d800d62542 | 13 | |
david8251 | 0:97c2d4128ff3 | 14 | while(1) { |
bastienvincke | 1:61d800d62542 | 15 | // Utilisation du capteur DHT11 |
bastienvincke | 1:61d800d62542 | 16 | err = dht11.readData(); // récupération des données |
bastienvincke | 1:61d800d62542 | 17 | if (err == 0) { |
bastienvincke | 1:61d800d62542 | 18 | temperature = dht11.ReadTemperature(CELCIUS); |
bastienvincke | 1:61d800d62542 | 19 | humidite = dht11.ReadHumidity(); |
bastienvincke | 1:61d800d62542 | 20 | point_rose = dht11.CalcdewPoint(dht11.ReadTemperature(CELCIUS), dht11.ReadHumidity()); |
bastienvincke | 1:61d800d62542 | 21 | printf("Temperature : %4.2f C \n",temperature); // envoie sur le port série des données (par défaut 9600bauds) |
bastienvincke | 1:61d800d62542 | 22 | printf("Humidite : %4.2f % \n",humidite); |
bastienvincke | 1:61d800d62542 | 23 | printf("Point rose : %4.2f C \n",point_rose); |
bastienvincke | 1:61d800d62542 | 24 | } else |
bastienvincke | 1:61d800d62542 | 25 | printf("\r\nErreur %i \n",err); |
bastienvincke | 1:61d800d62542 | 26 | |
bastienvincke | 1:61d800d62542 | 27 | // Clignotement de la led |
bastienvincke | 1:61d800d62542 | 28 | myled != myled; |
bastienvincke | 1:61d800d62542 | 29 | |
bastienvincke | 1:61d800d62542 | 30 | wait(2); |
david8251 | 0:97c2d4128ff3 | 31 | } |
david8251 | 0:97c2d4128ff3 | 32 | } |