S. Ken San
/
KL05Z_DHT11
Example using DHT11 with KL05Z. DHT library from teams/components/code/DHT
main.cpp@1:d2396e83a3b9, 2014-08-16 (annotated)
- Committer:
- kenno
- Date:
- Sat Aug 16 11:33:44 2014 +0000
- Revision:
- 1:d2396e83a3b9
- Parent:
- 0:052ced68c756
Initial commit.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kenno | 0:052ced68c756 | 1 | #include "mbed.h" |
kenno | 0:052ced68c756 | 2 | #include "DHT.h" |
kenno | 0:052ced68c756 | 3 | |
kenno | 0:052ced68c756 | 4 | DigitalOut myled(LED_GREEN); |
kenno | 0:052ced68c756 | 5 | Serial pc(USBTX, USBRX); // default baud 9600 |
kenno | 0:052ced68c756 | 6 | |
kenno | 0:052ced68c756 | 7 | DHT sensor(PTA11, DHT11); |
kenno | 0:052ced68c756 | 8 | |
kenno | 0:052ced68c756 | 9 | int main() { |
kenno | 0:052ced68c756 | 10 | int err; |
kenno | 0:052ced68c756 | 11 | pc.printf("\nDHT11 Test Program\n"); |
kenno | 0:052ced68c756 | 12 | |
kenno | 0:052ced68c756 | 13 | wait(1); // wait 1 sec for device stable |
kenno | 0:052ced68c756 | 14 | while (true) { |
kenno | 1:d2396e83a3b9 | 15 | myled = 0; // 0: on |
kenno | 0:052ced68c756 | 16 | err = sensor.readData(); |
kenno | 0:052ced68c756 | 17 | if (err == 0) { |
kenno | 0:052ced68c756 | 18 | pc.printf("Temperature is %4.2f C \r\n", sensor.ReadTemperature(CELCIUS)); |
kenno | 0:052ced68c756 | 19 | pc.printf("Temperature is %4.2f F \r\n", sensor.ReadTemperature(FARENHEIT)); |
kenno | 0:052ced68c756 | 20 | pc.printf("Humidity is %4.f % \r\n", sensor.ReadHumidity()); |
kenno | 0:052ced68c756 | 21 | printf("Dew point is %4.2f \r\n",sensor.CalcdewPoint(sensor.ReadTemperature(CELCIUS), sensor.ReadHumidity())); |
kenno | 0:052ced68c756 | 22 | printf("Dew point (fast) is %4.2f \r\n\n",sensor.CalcdewPointFast(sensor.ReadTemperature(CELCIUS), sensor.ReadHumidity())); |
kenno | 0:052ced68c756 | 23 | } |
kenno | 0:052ced68c756 | 24 | else { |
kenno | 0:052ced68c756 | 25 | printf("\r\nErr %i \n", err); |
kenno | 0:052ced68c756 | 26 | } |
kenno | 1:d2396e83a3b9 | 27 | myled = 1; |
kenno | 0:052ced68c756 | 28 | wait(15); |
kenno | 0:052ced68c756 | 29 | } |
kenno | 0:052ced68c756 | 30 | } |