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 00002 #include "mbed.h" 00003 #include "TextLCD.h" 00004 TextLCD lcd(p25,p26, p21, p22, p23, p24); // rs, e, d4, d5, d6, d7 00005 Serial pc(USBTX,USBRX); 00006 DigitalOut sensor1(p21); 00007 DigitalOut sensor2(p22); 00008 DigitalOut sensor3(p23); 00009 AnalogIn s_1(p15); 00010 AnalogIn s_2(p16); 00011 AnalogIn s_3(p17); 00012 AnalogIn s_4(p18); 00013 AnalogIn s_5(p19); 00014 AnalogIn b(p20); 00015 LocalFileSystem local("local"); 00016 char time1[16];//as our lcd is of 16 character it is so 00017 char date[16]; 00018 float a[6]; 00019 int time_clock; 00020 int j,k; 00021 float avg_sensorvalue1=0,avg_sensorvalue2=0; 00022 Timer timer; 00023 char c1[20]="sensor1"; 00024 char c2[20]="sensor2"; 00025 char c3[20]="sensor3"; 00026 char c4[20]="sensor4"; 00027 char c5[20]="sensor5"; 00028 char bat[20]="battery"; 00029 char d[30]="Date"; 00030 char t[30]="Time"; 00031 char c6[20]="time"; 00032 int main() 00033 { 00034 int i; 00035 set_time(1367038111); 00036 time_t seconds = time(NULL)+19800; // time(null) gives the GMT time which mustbe added with IST ie..GMTtime + 5 hr:30 min +19800 00037 strftime(time1,16,"%H/%M/%S",localtime(&seconds)); //this converts the value in seconds obtained above to human readable format and assigns it to the time_stamp which stores it 00038 strftime(date,16,"%d/%m/%y",localtime(&seconds)); 00039 00040 //fprintf(fp,"%s,%s,%s,%s,%s,%s,%s,%s\r",t,d,c1,c2,c3,c4,c5,battery); 00041 FILE *fp=fopen("/local/sensor1.csv","a"); 00042 00043 fprintf(fp,"%s,%s,%s,%s,%s,%s,%s,%s\r",t,d,c1,c2,c3,c4,c5,bat); 00044 while(1) 00045 { 00046 time_t seconds = time(NULL)+19800; 00047 strftime(time1,16,"%H/%M/%S",localtime(&seconds)); //this converts the value in seconds obtained above to human readable format and assigns it to the time_stamp which stores it 00048 strftime(date,16,"%d/%m/%y",localtime(&seconds)); 00049 /* for(i=0;i<=20;i++) 00050 { 00051 pulse=1; 00052 a[0]=a[0]+s_1.read(); 00053 a[1]=a[1]+s_2.read(); 00054 wait(0.005); 00055 pulse=0; 00056 wait(0.005); 00057 } 00058 a[0]=a[0]/21; 00059 a[1]=a[1]/21;*/ 00060 /*wait(1); 00061 a[1]=s_2.read(); 00062 wait(1); 00063 a[2]=s_3.read(); 00064 wait(1); 00065 a[3]=s_4.read(); 00066 wait(1); 00067 a[4]=s_5.read(); 00068 wait(1); 00069 a[5]=b.read(); 00070 wait(1); 00071 lcd.cls();//clear the lcd screen 00072 lcd.locate(0,0); 00073 lcd.printf("%.3f",a[0]); 00074 wait(2); 00075 lcd.cls();//clear the lcd screen 00076 lcd.locate(0,0); 00077 lcd.printf("%s,%s",time1,date); 00078 wait(3);*/ 00079 sensor1=1; 00080 sensor2=1; 00081 wait(2); 00082 a[0]=s_1.read(); 00083 a[1]=s_2.read(); 00084 wait(2); 00085 sensor1=0; 00086 sensor2=0; 00087 pc.printf("a[0]=%f,a[1]=%f",a[0],a[1]); 00088 fprintf(fp,"%s,%s,%0.6f,%.6f,%.6f,%.6f,%.6f,%.6f\r",time1,date,a[0],a[1],a[2],a[3],a[4],a[5]); 00089 wait(2); 00090 fclose(fp); 00091 FILE *fp=fopen("/local/sensor1.csv","a"); 00092 } 00093 00094 00095 } 00096 /* #include "mbed.h" 00097 #include "TextLCD.h" 00098 #include "string.h" 00099 #include "SDFileSystem.h" 00100 #include "PowerControl.h" 00101 #include "EthernetPowerControl.h" 00102 00103 void sendsms(float m); 00104 char a=0x1A,e=0x22; 00105 00106 char num[] = "9731892759"; 00107 #define USR_POWERDOWN (0x104) 00108 Serial uart(p9,p10); 00109 Serial GSM(p13, p14); // tx, rx 00110 Serial pc(USBTX,USBRX); 00111 00112 00113 Ticker sense; // Ticker to Interrupt the sleeping mode 00114 00115 TextLCD lcd(p24,p25,p26, p27, p28, p29, p30); // rs, rw, e, d4, d5, d6, d7 00116 AnalogIn Msensor_out(p20); 00117 AnalogIn Tsensor_out(p19); 00118 AnalogIn Lsensor_out(p18); 00119 DigitalOut sensors_vcc(p17); 00120 DigitalOut lcd2(p8); 00121 int k; 00122 char r[5]=""; 00123 00124 unsigned char i = 0; 00125 unsigned char j = 0; 00126 char time_stamp[16];//as our lcd is of 16 character it is so 00127 00128 float m,t,l; 00129 00130 00131 int semihost_powerdown() 00132 { 00133 uint32_t arg; 00134 return __semihost(USR_POWERDOWN, &arg); 00135 } 00136 00137 //////////////////////////////////////////////////////////////////// 00138 // fun() - it reads the sensor, writes to LCD and SD card and also senda the data on GSM 00139 //////////////////////////////////////////////////////////////////// 00140 00141 void fun() 00142 { 00143 sensors_vcc=1; 00144 m=Msensor_out.read(); //read the analog input from the pin15 and assign it to m 00145 t=Tsensor_out.read(); 00146 l=Lsensor_out.read(); 00147 wait(2); 00148 sensors_vcc=0; 00149 lcd.cls();//clear the lcd screen 00150 lcd.locate(0,0); 00151 lcd.printf("Welcome to WMS"); 00152 wait(3); 00153 00154 FILE *fp = fopen("/sd/mydir/sdtest.csv", "a"); 00155 if (fp == NULL) 00156 { 00157 error("Could not open file for write\n"); 00158 } 00159 fprintf(fp, "%d : %s \n",time_stamp,m); //Record Sensor data along with time stamp 00160 fclose(fp); 00161 wait(2); 00162 00163 00164 00165 00166 lcd.cls();//clear the lcd screen 00167 lcd.locate(0,0); 00168 lcd.printf("sending sms to"); 00169 wait(3); 00170 lcd.locate(0,1); 00171 lcd.printf("%s",num); 00172 wait(3); 00173 lcd.locate(0,0);//start displaying from zeroth column,zeroth row 00174 lcd.printf("%s",time_stamp);//diplays the human readable time which was stored in time_stamp. 00175 lcd.locate(0,1);//start displaying from zeroth column,first row 00176 lcd.printf("M%0.3f,%0.3f,L%0.3f",m,t,l);//display the value of analog input obtained in variable m 00177 wait(3); 00178 GSM.printf("AT+CMGS=%c%s%c\r\n",e,num,e); 00179 wait(3); 00180 GSM.printf("%s,Moisture%f",time_stamp,m); 00181 GSM.printf("%c",a); 00182 return ; 00183 } 00184 00185 00186 00187 int main() 00188 { 00189 lcd2=0; 00190 int result; 00191 GSM.baud(9600); 00192 pc.baud(9600); 00193 set_time( 1358319500); 00194 time_t seconds = time(NULL)+ 19800; // time(null) gives the GMT time which mustbe added with IST ie..GMTtime + 5 hr:30 min 00195 strftime(time_stamp, 16, "%d/%m/%y/%H/%M/%S", localtime(&seconds)); //this converts the value in seconds obtained above to human readable format and assigns it to the time_stamp which stores it 00196 00197 00198 PHY_PowerDown(); // PHY Powerdown 00199 result = semihost_powerdown(); //Semihost Powerdown 00200 sense.attach(&fun,30); // Excecute sd_write_read function every 5s 00201 //t.start(); //Start of timer to record Time Stamp 00202 while (1) 00203 { 00204 Sleep(); // Sleep mode to save power 00205 } 00206 00207 00208 } 00209 00210 00211 */ 00212 00213 00214 00215
Generated on Tue Jul 12 2022 21:35:22 by
1.7.2