Pablo Lopez
/
Nucleo_sHT-HumedadyTemperatura
Cod
main.cpp@0:f2be568faec6, 2019-05-12 (annotated)
- Committer:
- pablolopez89
- Date:
- Sun May 12 01:50:01 2019 +0000
- Revision:
- 0:f2be568faec6
Sensor de Humedad y Temperatura dht22
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pablolopez89 | 0:f2be568faec6 | 1 | #include "mbed.h" |
pablolopez89 | 0:f2be568faec6 | 2 | #include "DHT.h" |
pablolopez89 | 0:f2be568faec6 | 3 | |
pablolopez89 | 0:f2be568faec6 | 4 | DigitalOut myled(LED1); |
pablolopez89 | 0:f2be568faec6 | 5 | |
pablolopez89 | 0:f2be568faec6 | 6 | DHT sensor(PA_0,DHT22); // Use the SENdht22 sensor |
pablolopez89 | 0:f2be568faec6 | 7 | |
pablolopez89 | 0:f2be568faec6 | 8 | Serial PC(USBTX, USBRX);//Serial LOG |
pablolopez89 | 0:f2be568faec6 | 9 | |
pablolopez89 | 0:f2be568faec6 | 10 | int main() { |
pablolopez89 | 0:f2be568faec6 | 11 | int err; |
pablolopez89 | 0:f2be568faec6 | 12 | PC.printf("\r\nDHT Test program"); |
pablolopez89 | 0:f2be568faec6 | 13 | PC.printf("\r\n******************\r\n"); |
pablolopez89 | 0:f2be568faec6 | 14 | wait(1); // wait 1 second for device stable status |
pablolopez89 | 0:f2be568faec6 | 15 | while (1) { |
pablolopez89 | 0:f2be568faec6 | 16 | myled = 1; |
pablolopez89 | 0:f2be568faec6 | 17 | err = sensor.readData(); |
pablolopez89 | 0:f2be568faec6 | 18 | if (err == 0) { |
pablolopez89 | 0:f2be568faec6 | 19 | PC.printf("Temperature is %4.2f C \r\n",sensor.ReadTemperature(CELCIUS)); |
pablolopez89 | 0:f2be568faec6 | 20 | //PC.printf("Temperature is %4.2f F \r\n",sensor.ReadTemperature(FARENHEIT)); |
pablolopez89 | 0:f2be568faec6 | 21 | //PC.printf("Temperature is %4.2f K \r\n",sensor.ReadTemperature(KELVIN)); |
pablolopez89 | 0:f2be568faec6 | 22 | PC.printf("Humidity is %4.2f \r\n",sensor.ReadHumidity()); |
pablolopez89 | 0:f2be568faec6 | 23 | //PC.printf("Dew point is %4.2f \r\n",sensor.CalcdewPoint(sensor.ReadTemperature(CELCIUS), sensor.ReadHumidity())); |
pablolopez89 | 0:f2be568faec6 | 24 | //PC.printf("Dew point (fast) is %4.2f \r\n",sensor.CalcdewPointFast(sensor.ReadTemperature(CELCIUS), sensor.ReadHumidity())); |
pablolopez89 | 0:f2be568faec6 | 25 | } |
pablolopez89 | 0:f2be568faec6 | 26 | // else |
pablolopez89 | 0:f2be568faec6 | 27 | // PC.printf("\r\nErr %i \n",err); |
pablolopez89 | 0:f2be568faec6 | 28 | myled = 0; |
pablolopez89 | 0:f2be568faec6 | 29 | wait(1); |
pablolopez89 | 0:f2be568faec6 | 30 | } |
pablolopez89 | 0:f2be568faec6 | 31 | |
pablolopez89 | 0:f2be568faec6 | 32 | } |