Brendan Kelly / Mbed 2 deprecated mDot_LDR_DHT22_Example

Dependencies:   DHT22 mbed

Fork of mDot_AnalogIn_LDR_Example by Brendan Kelly

Files at this revision

API Documentation at this revision

Comitter:
kellybs1
Date:
Sun Aug 06 04:14:08 2017 +0000
Parent:
2:55d40722ec9d
Commit message:
testing dht22 ldr

Changed in this revision

DHT22.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DHT22.lib	Sun Aug 06 04:14:08 2017 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/Julepalme/code/DHT22/#7fd3ff04ae95
--- a/main.cpp	Sun Aug 06 00:24:22 2017 +0000
+++ b/main.cpp	Sun Aug 06 04:14:08 2017 +0000
@@ -8,15 +8,36 @@
  *
  * This program reads the analog input connected to pin PB_1 (UDK2
  * pin A0) and prints the result.
+ * And reads temperature/humidity from a DHT22 sensor and prints
+ * the result
  */
  
 #include "mbed.h"
+#include "DHT22.h"
+ 
+ DHT22 dht22(PA_1);
  
 int main() {
+    //analogue ldr pin
     AnalogIn a0(PB_1);
     
+    
     while (true) {
-        //read as float (0.0-1.0, multiply by 1000)
+        printf("-----------------------------\r\n");
+        int error = dht22.sample();
+        if (error == 1)
+        {
+            //it's required to divide these values by ten for some reason
+            float h = (float)dht22.getHumidity() / 10;
+            float t = (float)dht22.getTemperature() / 10;
+            printf("TempC: %2.1f, HumidP: %2.1f\r\n", t , h);
+        }
+        else
+        {
+            printf("Error: %d\n", error);
+        }
+        
+        //read LDR as float (0.0-1.0, multiply by 1000)
         float ldr1 = a0.read() * 1000;
         wait_ms(100);
         float ldr2 = a0.read() * 1000;
@@ -27,6 +48,6 @@
         float ldr = (ldr1 + ldr2 + ldr3) / 3;
         //output 3 digits . 3 decimal places
         printf("LDR: %3.3f\r\n", ldr);
-        wait(1);
+        wait(5);
     }
 }
\ No newline at end of file