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 "TextLCD.h" 00003 #include "main.h" 00004 00005 int ave5point(int source) 00006 { 00007 static int tmp[5] = {0}; 00008 static int sum = 0; 00009 00010 sum -= tmp[4]; 00011 sum += source; 00012 tmp[4] = tmp[3]; 00013 tmp[3] = tmp[2]; 00014 tmp[2] = tmp[1]; 00015 tmp[1] = tmp[0]; 00016 tmp[0] = source; 00017 00018 for(uint8_t i = 0; i < 5; i++){ 00019 if((tmp[i] > 180) || (tmp[i] < 10)){ 00020 return 0xFF; 00021 } 00022 } 00023 00024 return (int)(sum / 5.0); 00025 00026 } 00027 00028 void init() 00029 { 00030 device.baud(BAUD_RATE); 00031 device.printf("START"); 00032 device2.printf("START"); 00033 device.attach(&dev_tx,Serial::TxIrq); 00034 device.attach(&dev_rx,Serial::RxIrq); 00035 device2.attach(&dev2_tx,Serial::TxIrq); 00036 device2.attach(&dev2_rx,Serial::RxIrq); 00037 Button.mode(PullUp); 00038 00039 timer2.start(); 00040 00041 lcd.cls(); 00042 } 00043 00044 int main() 00045 { 00046 uint8_t flag = 0,state = 0; 00047 00048 init(); 00049 00050 for(;;){ 00051 if((!Button) && (!flag)){ 00052 wait(1); 00053 flag = 1; 00054 state = 1; 00055 }else if((!Button) && (flag)){ 00056 wait(1); 00057 flag = 0; 00058 state = 0; 00059 } 00060 00061 mbedleds = 0; 00062 00063 Ultrasonic(); 00064 IR_Position(); 00065 AveDistance = ave5point(Distance); 00066 00067 lcd.cls(); 00068 00069 if(state){ 00070 lcd.locate(0,0); 00071 lcd.printf("R:%d,F:%d",(int)ultrasonicValue[1],(int)ultrasonicValue[0]); 00072 lcd.locate(0,1); 00073 lcd.printf("L:%d,B:%d",(int)ultrasonicValue[3],(int)ultrasonicValue[2]); 00074 }else{ 00075 lcd.locate(0,0); 00076 lcd.printf("%d,%d",direction,data[2]);//data[2] 00077 lcd.locate(0,1); 00078 lcd.printf("%d,%d",AveDistance,data2[0]); 00079 } 00080 /* 00081 pc.printf("R:%d,\tF:%d\t",(int)ultrasonicValue[1],(int)ultrasonicValue[0]); 00082 pc.printf("L:%d,\tB:%d\n",(int)ultrasonicValue[3],(int)ultrasonicValue[2]); 00083 */ 00084 /* 00085 lcd.locate(0,0); 00086 lcd.printf("%d",(data[0] << 8) + data[1]); 00087 lcd.locate(0,1); 00088 lcd.printf("%d",data[2]); 00089 */ 00090 /* 00091 lcd.locate(0,0); 00092 lcd.printf("%d,%d",direction,data[3]);//data[2] 00093 lcd.locate(0,1); 00094 lcd.printf("%d",AveDistance); 00095 */ 00096 /* 00097 lcd.locate(0,0); 00098 lcd.printf("%d",data[0]); 00099 lcd.locate(0,1); 00100 lcd.printf("%d",data[1]);*/ 00101 } 00102 }
Generated on Tue Jul 12 2022 12:46:47 by
1.7.2