![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
basic temp probe
Fork of DHT-11 by
Revision 1:2fc8fc8a4b8d, committed 2018-03-01
- Comitter:
- hfoley
- Date:
- Thu Mar 01 19:02:34 2018 +0000
- Parent:
- 0:6e5d3c6e8715
- Commit message:
- basic temp probe code
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Mon Mar 03 19:57:32 2014 +0000 +++ b/main.cpp Thu Mar 01 19:02:34 2018 +0000 @@ -1,28 +1,43 @@ +/***************************************************************************** + * New Probe development + * RHT-03 + * + */ + #include "mbed.h" #include "DHT.h" -DigitalOut myled(LED1); +Serial pc(USBTX, USBRX); -DHT sensor(PTD4,SEN11301P); // Use the SEN11301P sensor - -int main() { +DHT Probe1(PTA4,RHT03); // Define the device + +int main() +{ int err; - printf("\r\nDHT Test program"); - printf("\r\n******************\r\n"); - wait(1); // wait 1 second for device stable status - while (1) { - myled = 1; - err = sensor.readData(); - if (err == 0) { - printf("Temperature is %4.2f C \r\n",sensor.ReadTemperature(CELCIUS)); - printf("Temperature is %4.2f F \r\n",sensor.ReadTemperature(FARENHEIT)); - printf("Temperature is %4.2f K \r\n",sensor.ReadTemperature(KELVIN)); - printf("Humidity is %4.2f \r\n",sensor.ReadHumidity()); - printf("Dew point is %4.2f \r\n",sensor.CalcdewPoint(sensor.ReadTemperature(CELCIUS), sensor.ReadHumidity())); - printf("Dew point (fast) is %4.2f \r\n",sensor.CalcdewPointFast(sensor.ReadTemperature(CELCIUS), sensor.ReadHumidity())); - } else - printf("\r\nErr %i \n",err); - myled = 0; - wait(15); + static float temp_F, temp_C; + static float humidity; + static float dew_pt_C, dew_pt_F; + + while(1) + { + err = Probe1.readData(); + if (err == 0) + { + temp_F = Probe1.ReadTemperature(FARENHEIT); + temp_C = Probe1.ReadTemperature(CELCIUS); + humidity = Probe1.ReadHumidity(); + dew_pt_C = Probe1.CalcdewPoint(temp_C, humidity); + dew_pt_F = dew_pt_C * 9 / 5 + 32; + + pc.printf("P2: Temp = %4.2f F Humidity = %4.2f DewPt = %4.2f \r\n", + temp_F, humidity, dew_pt_F); + } + else + { + pc.printf("error %d \r\n", err); + } + + wait(3); } -} \ No newline at end of file +} +