znrobotics 智能工场 / Mbed 2 deprecated Seeed_Arch_link_TempAndHumidity

Dependencies:   DHT22 mbed

Fork of Program2_TempAndHumidity by Robotics Kit Workshop

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"   // this tells us to load mbed related functions
00002 #include "DHT22.h"
00003 DHT22 dht22(p6);
00004 
00005 // this code runs when the microcontroller starts up
00006 int main()
00007 {
00008     int error = 0;
00009     float temp, hum;
00010 
00011     // spin a main loop all the time
00012     while(1) {
00013         wait(2.0f);
00014         
00015         // read data from the sensor
00016         error = dht22.sample();
00017         
00018         // read successfully
00019         if (1 == error) {
00020             // YOUR CODE GOES HERE, read temperature and humidity
00021             temp = //TODO;
00022             hum = //TODO;
00023             printf("temp: %2.2f  , hum:%2.2f    \r\n",temp,hum);
00024             
00025         } else {  // read unseccessfully
00026             printf("Error: %d\n", error);
00027         }
00028     }
00029 }