Raziel Lopez
/
FRDM-KL46Z_DTH_TEST
Based on another DHT library, this is just a modified one without using the RTC component
main.cpp@3:8c402316ce7e, 2019-01-06 (annotated)
- Committer:
- RazielLopez
- Date:
- Sun Jan 06 03:08:10 2019 +0000
- Revision:
- 3:8c402316ce7e
- Parent:
- 1:6df9454191d4
Agregando mejoras a la libreria original
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
RazielLopez | 0:b1384299f31c | 1 | #include "mbed.h" |
RazielLopez | 0:b1384299f31c | 2 | #include "DHT.h" |
RazielLopez | 0:b1384299f31c | 3 | |
RazielLopez | 0:b1384299f31c | 4 | |
RazielLopez | 0:b1384299f31c | 5 | |
RazielLopez | 0:b1384299f31c | 6 | #define DHT_TIPO DHT11 |
RazielLopez | 0:b1384299f31c | 7 | #define DHT_PIN PTA13 |
RazielLopez | 0:b1384299f31c | 8 | |
RazielLopez | 0:b1384299f31c | 9 | //Definicion de objjeto del sensor de humedad y temperatura |
RazielLopez | 0:b1384299f31c | 10 | DHT dht(DHT_PIN, DHT_TIPO); |
RazielLopez | 0:b1384299f31c | 11 | float measuredTemperature; |
RazielLopez | 0:b1384299f31c | 12 | int error_code; |
RazielLopez | 0:b1384299f31c | 13 | float measuredHumidity; |
RazielLopez | 0:b1384299f31c | 14 | |
RazielLopez | 0:b1384299f31c | 15 | // Host PC Communication channels |
RazielLopez | 0:b1384299f31c | 16 | Serial Terminal(USBTX, USBRX); // Tx, Rx |
RazielLopez | 0:b1384299f31c | 17 | |
RazielLopez | 0:b1384299f31c | 18 | int main() |
RazielLopez | 0:b1384299f31c | 19 | { |
RazielLopez | 0:b1384299f31c | 20 | |
RazielLopez | 0:b1384299f31c | 21 | while (true) { |
RazielLopez | 0:b1384299f31c | 22 | Terminal.printf("\rReading DHT ... "); |
RazielLopez | 0:b1384299f31c | 23 | error_code = dht.readData(); |
RazielLopez | 1:6df9454191d4 | 24 | if (error_code){ |
RazielLopez | 3:8c402316ce7e | 25 | Terminal.printf("\r\nError Code: %d \r\n", error_code); |
RazielLopez | 3:8c402316ce7e | 26 | Terminal.printf("\r\n"); |
RazielLopez | 3:8c402316ce7e | 27 | |
RazielLopez | 1:6df9454191d4 | 28 | Terminal.printf("\r\nData: %d %d %d %d %d \v\v\v\v", dht.DHT_data[0], dht.DHT_data[1],dht.DHT_data[2], dht.DHT_data[3], dht.DHT_data[4]); |
RazielLopez | 1:6df9454191d4 | 29 | } |
RazielLopez | 0:b1384299f31c | 30 | else{ |
RazielLopez | 0:b1384299f31c | 31 | measuredHumidity = dht.ReadHumidity(); //Se lee la humedad |
RazielLopez | 0:b1384299f31c | 32 | Terminal.printf("\r\nHumedad: %.2f", measuredHumidity); |
RazielLopez | 0:b1384299f31c | 33 | measuredTemperature = dht.ReadTemperature(CELCIUS); //Se lee la temperatura: CELCIUS=0,FARENHEIT=1,KELVIN=2 |
RazielLopez | 0:b1384299f31c | 34 | Terminal.printf("\r\nData: %d %d %d %d %d ", dht.DHT_data[0], dht.DHT_data[1],dht.DHT_data[2], dht.DHT_data[3], dht.DHT_data[4]); |
RazielLopez | 0:b1384299f31c | 35 | |
RazielLopez | 1:6df9454191d4 | 36 | Terminal.printf("\r\nTemperatura: %.2f \r\n\v\v\v\v\v\v\v\v\v", measuredTemperature); |
RazielLopez | 0:b1384299f31c | 37 | |
RazielLopez | 0:b1384299f31c | 38 | } |
RazielLopez | 0:b1384299f31c | 39 | wait(4); |
RazielLopez | 0:b1384299f31c | 40 | |
RazielLopez | 0:b1384299f31c | 41 | } |
RazielLopez | 0:b1384299f31c | 42 | } |