Tristan Hughes
/
RHT03_HelloWorld
A sample program showing how to read data from the RHT03
main.cpp@1:567ee42e14cb, 2012-08-29 (annotated)
- Committer:
- tristanjph
- Date:
- Wed Aug 29 13:21:19 2012 +0000
- Revision:
- 1:567ee42e14cb
- Parent:
- 0:4c2df3ab072c
First commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tristanjph | 0:4c2df3ab072c | 1 | #include "mbed.h" |
tristanjph | 0:4c2df3ab072c | 2 | #include "RHT03.h" //Include neede to use the RHT03 lib |
tristanjph | 0:4c2df3ab072c | 3 | |
tristanjph | 0:4c2df3ab072c | 4 | int main() |
tristanjph | 0:4c2df3ab072c | 5 | { |
tristanjph | 0:4c2df3ab072c | 6 | int done=0; |
tristanjph | 0:4c2df3ab072c | 7 | float temp,hum; |
tristanjph | 0:4c2df3ab072c | 8 | |
tristanjph | 0:4c2df3ab072c | 9 | RHT03 humtemp(p24); //Initalise the RHT03 (change pin number to the pin its connected to) |
tristanjph | 0:4c2df3ab072c | 10 | |
tristanjph | 0:4c2df3ab072c | 11 | while(!done) //Loop keeps running until RHT03 is read succesfully |
tristanjph | 0:4c2df3ab072c | 12 | { |
tristanjph | 0:4c2df3ab072c | 13 | wait(2); //Needed to make sure the sensor has time to initalise and so its not polled too quickly |
tristanjph | 0:4c2df3ab072c | 14 | if(humtemp.readData() == RHT_ERROR_NONE) done=1; //Request data from the RHT03 |
tristanjph | 0:4c2df3ab072c | 15 | } |
tristanjph | 0:4c2df3ab072c | 16 | |
tristanjph | 0:4c2df3ab072c | 17 | temp = humtemp.getTemperatureC(); //Gets the current temperature in centigrade |
tristanjph | 0:4c2df3ab072c | 18 | hum = humtemp.getHumidity(); //Gets the current humidity in percentage |
tristanjph | 0:4c2df3ab072c | 19 | |
tristanjph | 0:4c2df3ab072c | 20 | } |