temperature sensor application as a temperature based fan using the FRDM -K64F board
Fork of frdm_Grove_PIR_Example by
Diff: main.cpp
- Revision:
- 1:5c2fc62b9c0a
- Parent:
- 0:d444f103013a
--- a/main.cpp Thu Dec 31 23:29:45 2015 +0000 +++ b/main.cpp Sat May 07 01:27:48 2016 +0000 @@ -1,25 +1,28 @@ + #include "mbed.h" - -InterruptIn motion(D2); - -int motion_detected = 0; - -void irq_handler(void) +#include "DHT.h" + +DHT sensor(D4, DHT11); +DigitalOut vcc(PTA1); +int main() { - motion_detected = 1; -} - -int main(void) -{ - int cnt = 0; - motion.rise(&irq_handler); - + int error = 0; + float h = 0.0f, c = 0.0f, dp = 0.0f, dpf = 0.0f; + while(1) { - if(motion_detected) { - cnt++; - motion_detected = 0; - printf("Hello! I've detected %d times since reset\n", cnt); - } + wait(2.0f); + error = sensor.readData(); + if (0 == error) { + c = sensor.ReadTemperature(CELCIUS); + dp = sensor.CalcdewPoint(c, h); + dpf = sensor.CalcdewPointFast(c, h); + printf("Temperature in Celcius: %4.2f\n", c); + } else { + printf("Error: %d\n", error); + } while((int)c > 30){vcc=!vcc;} + while((int)c<30 ){vcc=0;} } } + + \ No newline at end of file