IoT Alarm System
Dependencies: ESP8266NodeMCUInterface JPEGCamera SDFileSystem IoT_Security xbee_lib
Fork of HUZZAHESP8266-web-control-LPC1768 by
main.cpp
00001 // ESP8266 Static page WEB server to control Mbed 00002 00003 #include "mbed.h" 00004 #include "JPEGCamera.h" 00005 #include "xbee.h" 00006 #include "ESP8266Interface.h" 00007 #include "TCPSocketConnection.h" 00008 #include "SDFileSystem.h" 00009 00010 SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board 00011 //#include "rtos.h" 00012 00013 //Print temperature from TMP36 analog temperature sensor 00014 /////////////////////////////////////////////////////////////////////////////// 00015 //Setup a new class for TMP36 sensor 00016 class TMP36 00017 { 00018 public: 00019 TMP36(PinName pin); 00020 TMP36(); 00021 operator float (); 00022 float read(); 00023 private: 00024 //class sets up the AnalogIn pin 00025 AnalogIn _pin; 00026 }; 00027 00028 TMP36::TMP36(PinName pin) : _pin(pin) 00029 { 00030 // _pin(pin) means pass pin to the AnalogIn constructor 00031 } 00032 00033 float TMP36::read() 00034 { 00035 //convert sensor reading to temperature in degrees C 00036 return ((_pin.read()*3.3)-0.500)*100.0; 00037 } 00038 //overload of float conversion (avoids needing to type .read() in equations) 00039 TMP36::operator float () 00040 { 00041 //convert sensor reading to temperature in degrees C 00042 return ((_pin.read()*3.3)-0.500)*100.0; 00043 } 00044 /////////////////////////////////////////////////////////////////////////////// 00045 00046 00047 00048 00049 00050 Serial pc(USBTX, USBRX); 00051 //Serial esp(p28, p27); // tx, rx 00052 LocalFileSystem local("local"); //save images on mbed 00053 00054 // Standard Mbed LED definitions 00055 DigitalOut led1(LED1); 00056 DigitalOut led2(LED2); 00057 DigitalOut led3(LED3); 00058 DigitalOut led4(LED4); 00059 00060 // some test values to show on web page 00061 AnalogIn Ain1(p18); 00062 AnalogIn Ain2(p19); 00063 00064 /* 00065 char ssid[32] = "hsd"; // enter WiFi router ssid inside the quotes 00066 char pwd [32] = "austin123"; // enter WiFi router password inside the quotes 00067 */ 00068 float temperature, AdcIn, Ht; 00069 float R1=100000, R2=10000; // resistor values to give a 10:1 reduction of measured AnalogIn voltage 00070 char Vcc[10]; 00071 char Temp[10]; 00072 00073 // things for sending/receiving data over serial 00074 volatile int tx_in=0; 00075 volatile int tx_out=0; 00076 volatile int rx_in=0; 00077 volatile int rx_out=0; 00078 const int buffer_size = 4095; 00079 char tx_buffer[buffer_size+1]; 00080 char rx_buffer[buffer_size+1]; 00081 void Tx_interrupt(); 00082 void Rx_interrupt(); 00083 void send_line(); 00084 void read_line(); 00085 void alarmPhoto(int); 00086 00087 int DataRX; 00088 int update; 00089 int count; 00090 char cmdbuff[1024]; 00091 char replybuff[4096]; 00092 char webdata[4096]; // This may need to be bigger depending on WEB browser used 00093 char webbuff[4096]; // Currently using 1986 characters, Increase this if more web page data added 00094 char timebuf[30]; 00095 void SendCMD(),getreply(),ReadWebData(),startserver(); 00096 void gettime(),setRTC(),getTemperature(); 00097 char rx_line[1024]; 00098 int port =80; // set server port 00099 int SERVtimeout =5; // set server timeout in seconds in case link breaks. 00100 struct tm t; 00101 // manual set RTC values 00102 int minute =00; // 0-59 00103 int hour =12; // 2-23 00104 int dayofmonth =26; // 1-31 00105 int month =8; // 1-12 00106 int year =15; // last 2 digits 00107 00108 PwmOut Alarm(p21); 00109 JPEGCamera camera(p13, p14); //Camera 00110 TMP36 myTMP36(p15); 00111 DigitalOut P16(p16); 00112 DigitalOut P17(p17); 00113 DigitalOut P19(p19); 00114 DigitalOut P20(p20); 00115 float tempC; 00116 xbee xbee2(p9,p10,p11); 00117 char read_data[202]; 00118 Serial esp(p28, p27); // tx, rx 00119 void Email(); 00120 //ESP8266Interface esp1(p28, p27, p26, 9600, 3000); 00121 //EthernetInterface eth; 00122 00123 //////// 00124 //tempC = myTMP36; 00125 ///printf(" T=%5.2F C \n\r", tempC);//for testing 00126 //if(tempC>45) { 00127 //add code 00128 //} 00129 /////// 00130 00131 int main() 00132 { 00133 camera.setPictureSize(JPEGCamera::SIZE320x240); 00134 pc.baud(9600); 00135 ////////////////////////////////xbee2.RecieveData(read_data,0); //ADD THIS BACK!!! 00136 // led3 = 1; 00137 // 00138 // ///////////Emailing the user 00139 // Email(); 00140 esp.baud(9600); 00141 led1=1,led2=0,led3=0, led4=0; 00142 // Setup a serial interrupt function to receive data 00143 esp.attach(&Rx_interrupt, Serial::RxIrq); 00144 // Setup a serial interrupt function to transmit data 00145 esp.attach(&Tx_interrupt, Serial::TxIrq); 00146 Alarm.period(1.0/100); 00147 if (time(NULL) < 1420070400) { 00148 setRTC(); 00149 } 00150 startserver(); 00151 DataRX=0; 00152 count=0; 00153 xbee2.RecieveData(read_data,0); 00154 led3 = 1; 00155 Alarm = 0.5; 00156 //Take photo 00157 alarmPhoto(5); //will be saved as PICT005.jpg 00158 //FILE *fp = fopen("/local/pict005.jpg", "w"); // Open "out.txt" on the local file system for writing 00159 // if (fp != NULL) { 00160 // pc.printf("File opens\n"); 00161 // } 00162 // mkdir("/sd/mydir", 0777); 00163 // FILE *fp1 = fopen("/sd/mydir/sdtest.jpg", "w"); 00164 // //fprintf(fp1, fp); 00165 // fclose(fp1); 00166 00167 // email the user 00168 // Can turn-off the alarm 00169 00170 // 00171 ///////////Emailing the user 00172 //Email(); 00173 // ESP8266Interface esp1(p28, p27, p26, 9600, 3000); 00174 // esp1.init(); 00175 // esp1.connect("ssid", "password"); 00176 // printf("IP Address is %s\n", esp1.getIPAddress()); 00177 // TCPSocketConnection sock; 00178 // //delete esp1; 00179 // 00180 // 00181 // sock.connect("blahblahmbed.comlu.com", 80); //http://blahblahmbed.comlu.com/ "mbed.org" 00182 // 00183 // char http_cmd[] = "GET http://blahblahmbed.comlu.com/index.php HTTP/1.0\n\n"; // /media/uploads/mbed_official/hello.txt 00184 // sock.send_all(http_cmd, sizeof(http_cmd)-1); 00185 // char buffer[300]; 00186 // int ret; 00187 // while (true) { 00188 // ret = sock.receive(buffer, sizeof(buffer)-1); 00189 // if (ret <= 0) break; 00190 // buffer[ret] = '\0'; 00191 // printf("Received %d chars from server:\n%s\n", ret, buffer); 00192 // } 00193 // sock.close(); 00194 // esp1.disconnect(); 00195 // ////////// 00196 //if (time(NULL) < 1420070400) { 00197 // setRTC(); 00198 // } 00199 // startserver(); 00200 //eth.init(); //Use DHCP 00201 //eth.connect(); 00202 //printf("IP Address is %s\n", eth.getIPAddress()); 00203 00204 //TCPSocketConnection sock; 00205 //sock.connect("blahblahmbed.comlu.com", 80); //http://blahblahmbed.comlu.com/ "mbed.org" 00206 00207 //char http_cmd[] = "GET http://blahblahmbed.comlu.com/index.php HTTP/1.0\n\n"; // /media/uploads/mbed_official/hello.txt 00208 //sock.send_all(http_cmd, sizeof(http_cmd)-1); 00209 while(1) { 00210 if(DataRX==1) { 00211 ReadWebData(); 00212 esp.attach(&Rx_interrupt, Serial::RxIrq); 00213 } 00214 if(update==1) // update time, hit count, and analog levels in the HUZZAH chip 00215 { 00216 // get new values 00217 gettime(); 00218 //gettemp(); 00219 //getbattery(); 00220 getTemperature(); 00221 //if (tempC > 27) { 00222 // Alarm = 0.5; 00223 // } 00224 count++; 00225 // send new values 00226 //sprintf(cmdbuff, "count,time,analog1,analog2=%d,\"%s\",\"%s\",\"%s\"\r\n",count,timebuf,Temp,Vcc); 00227 sprintf(cmdbuff, "count,time,tempC=%d,\"%s\",\"%f\"\r\n",count,timebuf,tempC); 00228 //esp1.send(cmdbuff, 1024); 00229 //esp1.recv(replybuff, sizeof(replybuff)); 00230 SendCMD(); 00231 getreply(); 00232 update=0; 00233 } 00234 } 00235 } 00236 00237 void Email() { 00238 /////////Emailing the user 00239 ESP8266Interface esp1(p28, p27, p26, 9600, 3000); 00240 esp1.init(); 00241 esp1.connect("ssid", "password"); 00242 printf("IP Address is %s\n", esp1.getIPAddress()); 00243 TCPSocketConnection sock; 00244 //delete esp1; 00245 00246 00247 sock.connect("blahblahmbed.comlu.com", 80); //http://blahblahmbed.comlu.com/ "mbed.org" 00248 00249 char http_cmd[] = "GET http://blahblahmbed.comlu.com/index.php HTTP/1.0\n\n"; // /media/uploads/mbed_official/hello.txt 00250 sock.send_all(http_cmd, sizeof(http_cmd)-1); 00251 char buffer[300]; 00252 int ret; 00253 while (true) { 00254 ret = sock.receive(buffer, sizeof(buffer)-1); 00255 if (ret <= 0) break; 00256 buffer[ret] = '\0'; 00257 printf("Received %d chars from server:\n%s\n", ret, buffer); 00258 } 00259 sock.close(); 00260 esp1.disconnect(); 00261 ////////// 00262 } 00263 00264 // Reads and processes GET and POST web data 00265 void ReadWebData() 00266 { 00267 wait_ms(200); 00268 esp.attach(NULL,Serial::RxIrq); 00269 DataRX=0; 00270 memset(webdata, '\0', sizeof(webdata)); 00271 strcpy(webdata, rx_buffer); 00272 memset(rx_buffer, '\0', sizeof(rx_buffer)); 00273 rx_in = 0; 00274 rx_out = 0; 00275 // check web data for form information 00276 if( strstr(webdata, "check=led1v") != NULL ) { 00277 led1=!led1; 00278 } 00279 if( strstr(webdata, "check=led2v") != NULL ) { 00280 led2=!led2; 00281 } 00282 if( strstr(webdata, "check=led3v") != NULL ) { 00283 led3=!led3; 00284 } 00285 if( strstr(webdata, "check=led4v") != NULL ) { 00286 led4=!led4; 00287 } 00288 if( strstr(webdata, "check=speakeron") != NULL ) { 00289 if (Alarm == 0.5){Alarm=0.0;} 00290 else Alarm=0.5; 00291 } 00292 if( strstr(webdata, "check=photo") != NULL ) { 00293 alarmPhoto(count); 00294 FILE *fp = fopen("/local/pict003.jpg", "w"); // Open "out.txt" on the local file system for writing 00295 if (fp != NULL) { 00296 pc.printf("File opens\n"); 00297 } 00298 fclose(fp); 00299 } 00300 if( strstr(webdata, "POST") != NULL ) { // set update flag if POST request 00301 update=1; 00302 } 00303 if( strstr(webdata, "GET") != NULL && strstr(webdata, "favicon") == NULL ) { // set update flag for GET request but do not want to update for favicon requests 00304 update=1; 00305 } 00306 } 00307 // Starts webserver 00308 void startserver() 00309 { 00310 gettime(); 00311 //gettemp(); 00312 //getbattery(); 00313 pc.printf("++++++++++ Resetting ESP ++++++++++\r\n"); 00314 strcpy(cmdbuff,"node.restart()\r\n"); 00315 SendCMD(); 00316 wait(2); 00317 getreply(); 00318 00319 pc.printf("\n++++++++++ Starting Server ++++++++++\r\n> "); 00320 00321 // initial values 00322 sprintf(cmdbuff, "count,time,analog1,analog2=0,\"%s\",\"%s\",\"%s\"\r\n",timebuf,Temp,Vcc); 00323 SendCMD(); 00324 getreply(); 00325 wait(0.5); 00326 00327 //create server 00328 sprintf(cmdbuff, "srv=net.createServer(net.TCP,%d)\r\n",SERVtimeout); 00329 SendCMD(); 00330 getreply(); 00331 wait(0.5); 00332 strcpy(cmdbuff,"srv:listen(80,function(conn)\r\n"); 00333 SendCMD(); 00334 getreply(); 00335 wait(0.3); 00336 strcpy(cmdbuff,"conn:on(\"receive\",function(conn,payload) \r\n"); 00337 SendCMD(); 00338 getreply(); 00339 wait(0.3); 00340 00341 //print data to mbed 00342 strcpy(cmdbuff,"print(payload)\r\n"); 00343 SendCMD(); 00344 getreply(); 00345 wait(0.2); 00346 00347 strcpy(cmdbuff,"conn:send('<!DOCTYPE html><html><body><h1>IoT Alarm System</h1>')\r\n"); 00348 SendCMD(); 00349 getreply(); 00350 wait(0.4); 00351 // strcpy(cmdbuff,"conn:send('<body style=\"background-color:#FF0000;>')\r\n"); 00352 // SendCMD(); 00353 // getreply(); 00354 // wait(0.4); 00355 strcpy(cmdbuff,"conn:send('Hit count: '..count..'')\r\n"); 00356 SendCMD(); 00357 getreply(); 00358 wait(0.2); 00359 strcpy(cmdbuff,"conn:send('<br>Last hit (based on mbed RTC time): '..time..'<br><hr>')\r\n"); 00360 SendCMD(); 00361 getreply(); 00362 wait(0.4); 00363 //strcpy(cmdbuff,"conn:send('Analog 1: '..analog1..' V<br>Analog 2: '..analog2..' V<br><hr>')\r\n"); 00364 // SendCMD(); 00365 // getreply(); 00366 // wait(0.3); 00367 strcpy(cmdbuff,"conn:send('Temperature: '..tempC..'')\r\n"); 00368 SendCMD(); 00369 getreply(); 00370 wait(0.3); 00371 00372 strcpy(cmdbuff,"conn:send('<form method=\"POST\"')\r\n"); 00373 SendCMD(); 00374 getreply(); 00375 wait(0.3); 00376 strcpy(cmdbuff, "conn:send('<p><input type=\"checkbox\" name=\"check\" value=\"led1v\"> flip LED1')\r\n"); 00377 SendCMD(); 00378 getreply(); 00379 wait(0.3); 00380 ///////////////////////////////////////////////////////////////////////////////////////////////////////// 00381 // strcpy(cmdbuff, "conn:send('<p><input type=\"image\" src=\"/PICT002.jpg\" alt=\"Submit\"> blah')\r\n"); 00382 // SendCMD(); 00383 // getreply(); 00384 // wait(0.3); 00385 ///////////////////////////////////////////////////////////////////////////////////////////////////////// 00386 00387 strcpy(cmdbuff, "conn:send('<p><input type=\"checkbox\" name=\"check\" value=\"led2v\"> flip LED2')\r\n"); 00388 SendCMD(); 00389 getreply(); 00390 wait(0.3); 00391 strcpy(cmdbuff, "conn:send('<p><input type=\"checkbox\" name=\"check\" value=\"led3v\"> flip LED3')\r\n"); 00392 SendCMD(); 00393 getreply(); 00394 wait(0.3); 00395 strcpy(cmdbuff, "conn:send('<p><input type=\"checkbox\" name=\"check\" value=\"led4v\"> flip LED4')\r\n"); 00396 SendCMD(); 00397 getreply(); 00398 wait(0.3); 00399 00400 strcpy(cmdbuff, "conn:send('<p><input type=\"checkbox\" name=\"check\" value=\"speakeron\"> Alarm')\r\n"); 00401 SendCMD(); 00402 getreply(); 00403 wait(0.3); 00404 strcpy(cmdbuff, "conn:send('<p><input type=\"checkbox\" name=\"check\" value=\"photo\"> Take Photo')\r\n"); 00405 SendCMD(); 00406 getreply(); 00407 wait(0.3); 00408 00409 strcpy(cmdbuff,"conn:send('<p><input type=\"submit\" value=\"send-refresh\"></form>')\r\n"); 00410 SendCMD(); 00411 getreply(); 00412 wait(0.3); 00413 strcpy(cmdbuff, "conn:send('<p><h2>How to use:</h2><ul><li>Select a checkbox to flip on/off</li><li>Click Send-Refresh to send data and refresh values</li></ul></body></html>')\r\n"); 00414 SendCMD(); 00415 getreply(); 00416 wait(0.5); 00417 // end web page data 00418 strcpy(cmdbuff, "conn:on(\"sent\",function(conn) conn:close() end)\r\n"); // close current connection 00419 SendCMD(); 00420 getreply(); 00421 wait(0.3); 00422 strcpy(cmdbuff, "end)\r\n"); 00423 SendCMD(); 00424 getreply(); 00425 wait(0.2); 00426 strcpy(cmdbuff, "end)\r\n"); 00427 SendCMD(); 00428 getreply(); 00429 wait(0.2); 00430 00431 strcpy(cmdbuff, "tmr.alarm(0, 1000, 1, function()\r\n"); 00432 SendCMD(); 00433 getreply(); 00434 wait(0.2); 00435 strcpy(cmdbuff, "if wifi.sta.getip() == nil then\r\n"); 00436 SendCMD(); 00437 getreply(); 00438 wait(0.2); 00439 strcpy(cmdbuff, "print(\"Connecting to AP...\\n\")\r\n"); 00440 SendCMD(); 00441 getreply(); 00442 wait(0.2); 00443 strcpy(cmdbuff, "else\r\n"); 00444 SendCMD(); 00445 getreply(); 00446 wait(0.2); 00447 strcpy(cmdbuff, "ip, nm, gw=wifi.sta.getip()\r\n"); 00448 SendCMD(); 00449 getreply(); 00450 wait(0.2); 00451 strcpy(cmdbuff,"print(\"IP Address: \",ip)\r\n"); 00452 SendCMD(); 00453 getreply(); 00454 wait(0.2); 00455 strcpy(cmdbuff,"tmr.stop(0)\r\n"); 00456 SendCMD(); 00457 getreply(); 00458 wait(0.2); 00459 strcpy(cmdbuff,"end\r\n"); 00460 SendCMD(); 00461 getreply(); 00462 wait(0.2); 00463 strcpy(cmdbuff,"end)\r\n"); 00464 SendCMD(); 00465 getreply(); 00466 wait(0.2); 00467 00468 pc.printf("\n\n++++++++++ Ready ++++++++++\r\n\n"); 00469 } 00470 00471 00472 // ESP Command data send 00473 void SendCMD() 00474 { 00475 int i; 00476 char temp_char; 00477 bool empty; 00478 i = 0; 00479 // Start Critical Section - don't interrupt while changing global buffer variables 00480 NVIC_DisableIRQ(UART1_IRQn); 00481 empty = (tx_in == tx_out); 00482 while ((i==0) || (cmdbuff[i-1] != '\n')) { 00483 // Wait if buffer full 00484 if (((tx_in + 1) % buffer_size) == tx_out) { 00485 // End Critical Section - need to let interrupt routine empty buffer by sending 00486 NVIC_EnableIRQ(UART1_IRQn); 00487 while (((tx_in + 1) % buffer_size) == tx_out) { 00488 } 00489 // Start Critical Section - don't interrupt while changing global buffer variables 00490 NVIC_DisableIRQ(UART1_IRQn); 00491 } 00492 tx_buffer[tx_in] = cmdbuff[i]; 00493 i++; 00494 tx_in = (tx_in + 1) % buffer_size; 00495 } 00496 if (esp.writeable() && (empty)) { 00497 temp_char = tx_buffer[tx_out]; 00498 tx_out = (tx_out + 1) % buffer_size; 00499 // Send first character to start tx interrupts, if stopped 00500 esp.putc(temp_char); 00501 } 00502 // End Critical Section 00503 NVIC_EnableIRQ(UART1_IRQn); 00504 return; 00505 } 00506 00507 // Get Command and ESP status replies 00508 void getreply() 00509 { 00510 read_line(); 00511 sscanf(rx_line,replybuff); 00512 } 00513 00514 // Read a line from the large rx buffer from rx interrupt routine 00515 void read_line() { 00516 int i; 00517 i = 0; 00518 // Start Critical Section - don't interrupt while changing global buffer variables 00519 NVIC_DisableIRQ(UART1_IRQn); 00520 // Loop reading rx buffer characters until end of line character 00521 while ((i==0) || (rx_line[i-1] != '\r')) { 00522 // Wait if buffer empty 00523 if (rx_in == rx_out) { 00524 // End Critical Section - need to allow rx interrupt to get new characters for buffer 00525 NVIC_EnableIRQ(UART1_IRQn); 00526 while (rx_in == rx_out) { 00527 } 00528 // Start Critical Section - don't interrupt while changing global buffer variables 00529 NVIC_DisableIRQ(UART1_IRQn); 00530 } 00531 rx_line[i] = rx_buffer[rx_out]; 00532 i++; 00533 rx_out = (rx_out + 1) % buffer_size; 00534 } 00535 // End Critical Section 00536 NVIC_EnableIRQ(UART1_IRQn); 00537 rx_line[i-1] = 0; 00538 return; 00539 } 00540 00541 00542 // Interupt Routine to read in data from serial port 00543 void Rx_interrupt() { 00544 DataRX=1; 00545 //led3=1; 00546 // Loop just in case more than one character is in UART's receive FIFO buffer 00547 // Stop if buffer full 00548 while ((esp.readable()) && (((rx_in + 1) % buffer_size) != rx_out)) { 00549 rx_buffer[rx_in] = esp.getc(); 00550 // Uncomment to Echo to USB serial to watch data flow 00551 pc.putc(rx_buffer[rx_in]); 00552 rx_in = (rx_in + 1) % buffer_size; 00553 } 00554 //led3=0; 00555 return; 00556 } 00557 00558 00559 // Interupt Routine to write out data to serial port 00560 void Tx_interrupt() { 00561 //led2=1; 00562 // Loop to fill more than one character in UART's transmit FIFO buffer 00563 // Stop if buffer empty 00564 while ((esp.writeable()) && (tx_in != tx_out)) { 00565 esp.putc(tx_buffer[tx_out]); 00566 tx_out = (tx_out + 1) % buffer_size; 00567 } 00568 //led2=0; 00569 return; 00570 } 00571 00572 void gettime() 00573 { 00574 time_t seconds = time(NULL); 00575 strftime(timebuf,50,"%H:%M:%S %a %d %b %y", localtime(&seconds)); 00576 } 00577 00578 void setRTC() 00579 { 00580 t.tm_sec = (0); // 0-59 00581 t.tm_min = (minute); // 0-59 00582 t.tm_hour = (hour); // 0-23 00583 t.tm_mday = (dayofmonth); // 1-31 00584 t.tm_mon = (month-1); // 0-11 "0" = Jan, -1 added for Mbed RCT clock format 00585 t.tm_year = ((year)+100); // year since 1900, current DCF year + 100 + 1900 = correct year 00586 set_time(mktime(&t)); // set RTC clock 00587 } 00588 00589 // Analog in example 00590 void getTemperature() 00591 { 00592 tempC=myTMP36; 00593 //Ht = (AdcIn*3.3); // set the numeric to the exact MCU analog reference voltage for greater accuracy 00594 //tempC = 5.0; 00595 00596 if (tempC > 30.0) { 00597 //then alarm goes off (speaker) 00598 //Message sent to webpage (maybe email or text) 00599 00600 //Take input from webpage to turn it off 00601 } 00602 00603 //sprintf(Vcc,"%2.3f",tempC); 00604 } 00605 void alarmPhoto(int i) 00606 { 00607 if (camera.isReady()) { 00608 char filename[32]; 00609 sprintf(filename, "/local/pict%03d.jpg", i); 00610 //string a = string(filename); 00611 pc.printf("Picture: %s ", filename); 00612 if (camera.takePicture(filename)) 00613 { 00614 while (camera.isProcessing()) 00615 { 00616 camera.processPicture(); 00617 } 00618 led1 = 1; //show successful picture was taken 00619 wait(2.0); 00620 led1 = 0; 00621 } 00622 else 00623 { 00624 pc.printf("take picture failed\n"); 00625 led3 = 1; //show picture take failed 00626 wait(2.0); 00627 led3 = 0; 00628 } 00629 } 00630 else 00631 { 00632 pc.printf("camera is not ready\n"); 00633 led4 = 1; //show camera is not ready 00634 wait(2.0); 00635 led4 = 0; 00636 } 00637 led2 = 1; //show end of sequence 00638 wait(2.0); 00639 led2 = 0; 00640 pc.printf("Photo taken\n"); 00641 //return filename; 00642 } 00643 00644 00645 00646 // Analog in example 00647 //void getbattery() 00648 //{ 00649 // AdcIn=Ain1.read(); 00650 // Ht = (AdcIn*3.3); // set the numeric to the exact MCU analog reference voltage for greater accuracy 00651 // sprintf(Vcc,"%2.3f",Ht); 00652 //} 00653 //// Temperature example 00654 //void gettemp() 00655 //{ 00656 // 00657 // AdcIn=Ain2.read(); 00658 // Ht = (AdcIn*3.3); // set the numeric to the exact MCU analog reference voltage for greater accuracy 00659 // sprintf(Temp,"%2.3f",Ht); 00660 //}
Generated on Wed Jul 20 2022 05:10:04 by
1.7.2
