Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 #include "mbed.h" 00002 #include "DHT/DHT.h" 00003 #include <string> 00004 00005 using namespace std; 00006 00007 DHT sensor(A2,DHT22); 00008 Serial pc(SERIAL_TX,SERIAL_RX); 00009 Serial xbee(A0,A1); 00010 00011 void getTemperatueHumidity(){ 00012 int err; 00013 pc.printf("\r\nStarting to gather temperature and humidity......\n"); 00014 pc.printf("\r\n******************\r\n"); 00015 wait(1); // wait 1 second for device stable status 00016 while (1) { 00017 00018 err = sensor.readData(); 00019 if (err == 0) { 00020 pc.printf("Temperature is %4.2f C \r\n",sensor.ReadTemperature(CELCIUS)); 00021 pc.printf("Temperature is %4.2f F \r\n",sensor.ReadTemperature(FARENHEIT)); 00022 pc.printf("Temperature is %4.2f K \r\n",sensor.ReadTemperature(KELVIN)); 00023 pc.printf("Humidity is %4.2f \r\n",sensor.ReadHumidity()); 00024 00025 xbee.printf("Temperature is %4.2f C \r\n",sensor.ReadTemperature(CELCIUS)); 00026 xbee.printf("Temperature is %4.2f F \r\n",sensor.ReadTemperature(FARENHEIT)); 00027 xbee.printf("Temperature is %4.2f K \r\n",sensor.ReadTemperature(KELVIN)); 00028 xbee.printf("Humidity is %4.2f \r\n",sensor.ReadHumidity()); 00029 00030 return; 00031 } else { 00032 pc.printf("\r\nErr %i \n",err); 00033 xbee.printf("\r\nErr %i \n",err); 00034 } 00035 wait(5); 00036 } 00037 } 00038 00039 void printInit(){ 00040 xbee.printf("Awaiting User Command....\n"); 00041 } 00042 00043 int main() { 00044 00045 char a; 00046 printInit(); 00047 while(1){ 00048 a = xbee.getc(); 00049 if(a == 'T'){ 00050 getTemperatueHumidity(); 00051 a = NULL; 00052 printInit(); 00053 } 00054 00055 if( a == 'G'){ 00056 //GPS function 00057 a = NULL; 00058 printInit(); 00059 } 00060 } 00061 } 00062
Generated on Fri Jul 15 2022 21:23:56 by
1.7.2