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.
Dependencies: BMP180 N5110 mbed
main.cpp
00001 /** 00002 @Header file name.h 00003 @Project-D Weather Station 00004 @file main.cpp 00005 @author Li XingYu 00006 @date May 2015 00007 */ 00008 00009 #include "mbed.h" 00010 #include "N5110.h" 00011 #include "BMP180.h" 00012 00013 /** 00014 @namespace lcd,bmp180,serial 00015 @brief serial connects to micro-controller 00016 @brief 00017 */ 00018 00019 //The pins of N5110, BMP180 which are connected to micro-controller 00020 N5110 lcd(p7,p8,p9,p10,p11,p13,p22); 00021 BMP180 bmp180(p28,p27); 00022 Serial serial(USBTX,USBRX);// The tool which sets the date 00023 00024 /** 00025 add up one integer variable 00026 @param setTimerFlag - integer to add 00027 creat two functions 00028 @param serialISR - function to add 00029 @param setTime - function to add 00030 */ 00031 void serialISR();// ISR that is called when serial data is received 00032 void setTime();// function to set the UNIX time 00033 int setTimerFlag = 0;// flag for ISR 00034 00035 char rxString[16];// buffer to store received string 00036 00037 00038 /** 00039 @Boot Screen 00040 Sset Brightness 00041 @Set date 00042 @Connect LCD and sensor to micro-controller 00043 @Display temperature and pressure 00044 */ 00045 00046 int main() 00047 { 00048 00049 lcd.init(); 00050 //Boot Screen 00051 lcd.printString("Project-D",2,1);//First line and coordinate 00052 lcd.printString("Weather",2,2);//Second line and coordinate 00053 lcd.printString("station",2,3);//Third line and coordinate 00054 wait(2.0);//Wait 2 secs and turn into next interface 00055 lcd.clear();//Clear 00056 lcd.setBrightness(0.1);//Screen Brightness 00057 bmp180.init(); 00058 Measurement measurement; 00059 //RTC 00060 serial.attach(&serialISR);//Set the time 00061 char t[30];//array to t 00062 while(1) { 00063 time_t seconds = time(NULL); 00064 00065 strftime(t, 30 , "%X %D",localtime(&seconds));//The form of date 00066 00067 serial.printf("Time = %s\n" ,t);// The form of date displaying on the screen 00068 lcd.printString(t,0,5);//The coordinate of date 00069 wait(1.0); 00070 if(setTimerFlag) // if updated time has been sent 00071 { 00072 setTimerFlag = 0;// clear flag 00073 setTime(); // update time 00074 00075 } 00076 00077 00078 measurement = bmp180.readValues();// The values received by BMP180 00079 char buffer[14];//array for buffer 00080 int length = sprintf(buffer,"T= %.2f C",measurement.temperature);//Thr form of values of temperature 00081 if(length<=14)//If less than 14 words a line 00082 lcd.printString(buffer,0,1); // The coordinate of date 00083 char buffer2[14];//14 words a line 00084 length =sprintf(buffer2,"P = %.2f mb",measurement.pressure);//The form of values of pressure 00085 if(length<=14)//If less than 14 words a line 00086 lcd.printString(buffer2,0,2); //The coordinate of values 00087 wait(1.0);//wait 1 sec 00088 } 00089 00090 00091 00092 } 00093 00094 /** 00095 add up one integer variable 00096 @setTime - print it for debugging 00097 @timeflag - read rx string into buffer 00098 @param time - integer to add 00099 @atoi - update the time 00100 */ 00101 00102 void setTime()// print time for debugging 00103 { 00104 serial.printf("set_time - %s",rxString);// atoi() converts a string to an integer 00105 00106 int time = atoi(rxString);// update the time 00107 00108 set_time(time); 00109 } 00110 00111 void serialISR() 00112 { 00113 // when a serial interrupt occurs, read rx string into buffer 00114 serial.gets(rxString,16); 00115 // set flag 00116 setTimerFlag = 1; 00117 } 00118 00119 00120 00121 00122 00123 00124 00125
Generated on Thu Jul 14 2022 19:37:50 by
