Robotics Kit Workshop
/
Program2_TempAndHumidity
read the temperature and humidity from the sensor and print them
main.cpp
- Committer:
- mbedAustin
- Date:
- 2016-05-28
- Revision:
- 6:3b1739d2a2c6
- Parent:
- 5:176e1bc77ec2
File content as of revision 6:3b1739d2a2c6:
#include "mbed.h" // this tells us to load mbed related functions #include "DHT22.h" DHT22 dht22(p6); // this code runs when the microcontroller starts up int main() { int error = 0; float temp, hum; // spin a main loop all the time while(1) { wait(2.0f); // read data from the sensor error = dht22.sample(); // read successfully if (1 == error) { // YOUR CODE GOES HERE, read temperature and humidity temp = //TODO; hum = //TODO; printf("temp: %2.2f , hum:%2.2f \r\n",temp,hum); } else { // read unseccessfully printf("Error: %d\n", error); } } }