A sample program showing how to read data from the RHT03

Dependencies:   RHT03 mbed

main.cpp

Committer:
tristanjph
Date:
2012-08-29
Revision:
1:567ee42e14cb
Parent:
0:4c2df3ab072c

File content as of revision 1:567ee42e14cb:

#include "mbed.h"
#include "RHT03.h" //Include neede to use the RHT03 lib

int main()
{
    int done=0;
    float temp,hum;

    RHT03 humtemp(p24); //Initalise the RHT03 (change pin number to the pin its connected to)

    while(!done) //Loop keeps running until RHT03 is read succesfully
    {
        wait(2); //Needed to make sure the sensor has time to initalise and so its not polled too quickly
        if(humtemp.readData() == RHT_ERROR_NONE) done=1; //Request data from the RHT03
    }
    
    temp = humtemp.getTemperatureC(); //Gets the current temperature in centigrade
    hum = humtemp.getHumidity(); //Gets the current humidity in percentage

}