asf

Dependencies:   RHT03 mbed

Fork of mbed_indeklima by Benjamin Juul

Committer:
mathiasoem
Date:
Tue Oct 28 09:25:20 2014 +0000
Revision:
1:da3579be9a8d
Parent:
0:fb4d631a5994
fa

Who changed what in which revision?

UserRevisionLine numberNew contents of line
201209650 0:fb4d631a5994 1 #include "mbed.h"
201209650 0:fb4d631a5994 2 #include "RHT03.h" //Include neede to use the RHT03 lib
201209650 0:fb4d631a5994 3
201209650 0:fb4d631a5994 4 Serial pc(USBTX, USBRX);
201209650 0:fb4d631a5994 5
201209650 0:fb4d631a5994 6 int done=0;
201209650 0:fb4d631a5994 7 float temp,hum;
201209650 0:fb4d631a5994 8
201209650 0:fb4d631a5994 9 RHT03 humtemp(p21); //Initalise the RHT03 (change pin number to the pin its connected to)
201209650 0:fb4d631a5994 10
201209650 0:fb4d631a5994 11 DigitalOut lysdiode(p14);
201209650 0:fb4d631a5994 12
201209650 0:fb4d631a5994 13 void tickerFunction() {
201209650 0:fb4d631a5994 14
201209650 0:fb4d631a5994 15 //Hum & Temp
201209650 0:fb4d631a5994 16 while(!done) { //Loop keeps running until RHT03 is read succesfully
201209650 0:fb4d631a5994 17 wait(2); //Needed to make sure the sensor has time to initalise and so its not polled too quickly
201209650 0:fb4d631a5994 18 if(humtemp.readData() == RHT_ERROR_NONE) done=1; //Request data from the RHT03
201209650 0:fb4d631a5994 19 }
201209650 0:fb4d631a5994 20
201209650 0:fb4d631a5994 21 done = 0;
201209650 0:fb4d631a5994 22 temp = humtemp.getTemperatureC(); //Gets the current temperature in centigrade
201209650 0:fb4d631a5994 23 hum = humtemp.getHumidity(); //Gets the current humidity in percentage
201209650 0:fb4d631a5994 24
mathiasoem 1:da3579be9a8d 25 if (hum > 50 || temp > 23) {
201209650 0:fb4d631a5994 26 lysdiode = 0;
201209650 0:fb4d631a5994 27 } else {
201209650 0:fb4d631a5994 28 lysdiode = 1;
201209650 0:fb4d631a5994 29 }
201209650 0:fb4d631a5994 30
201209650 0:fb4d631a5994 31 //Print data
201209650 0:fb4d631a5994 32 pc.printf("Hum: %0.2f, Temp: %0.2f\n", hum, temp);
201209650 0:fb4d631a5994 33
201209650 0:fb4d631a5994 34 }
201209650 0:fb4d631a5994 35
201209650 0:fb4d631a5994 36 Ticker ticker;
201209650 0:fb4d631a5994 37
201209650 0:fb4d631a5994 38 int main()
201209650 0:fb4d631a5994 39 {
201209650 0:fb4d631a5994 40
201209650 0:fb4d631a5994 41 pc.printf("Hello\n");
201209650 0:fb4d631a5994 42
201209650 0:fb4d631a5994 43 ticker.attach(&tickerFunction, 5.0); //update every 1 sec
201209650 0:fb4d631a5994 44
201209650 0:fb4d631a5994 45 while (1) {
201209650 0:fb4d631a5994 46 }
201209650 0:fb4d631a5994 47 }