A sample program showing how to read data from the RHT03

Dependencies:   RHT03 mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "RHT03.h" //Include neede to use the RHT03 lib
00003 
00004 int main()
00005 {
00006     int done=0;
00007     float temp,hum;
00008 
00009     RHT03 humtemp(p24); //Initalise the RHT03 (change pin number to the pin its connected to)
00010 
00011     while(!done) //Loop keeps running until RHT03 is read succesfully
00012     {
00013         wait(2); //Needed to make sure the sensor has time to initalise and so its not polled too quickly
00014         if(humtemp.readData() == RHT_ERROR_NONE) done=1; //Request data from the RHT03
00015     }
00016     
00017     temp = humtemp.getTemperatureC(); //Gets the current temperature in centigrade
00018     hum = humtemp.getHumidity(); //Gets the current humidity in percentage
00019 
00020 }