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: mbed
main.cpp
00001 #include "mbed.h" 00002 #include "ATP3012.h" 00003 00004 Serial bluetooth(p9,p10); //tx, rx 00005 ATP3012 talk(P0_5, P0_4); // sda, scl 00006 00007 PwmOut Rin(P0_8); 00008 PwmOut Lin(P0_9); 00009 PwmOut S40kHz(P0_21); 00010 DigitalOut IN1(P0_11); 00011 DigitalOut IN2(P0_12); 00012 AnalogIn Ain(P0_13); 00013 DigitalOut StopSignal(P0_20); 00014 DigitalOut Light(P0_16); 00015 00016 int main() { 00017 bluetooth.baud(115200); 00018 int32_t i, j; 00019 int32_t count=10000; 00020 uint8_t buf='5'; 00021 char moji[64]; 00022 int32_t onsei=0; 00023 00024 char* LightOn[64] = { "raitoon.\r", "tentou.\r" } ; 00025 char* LightOff[64] = { "raito/ohu.\r", "syoutou.\r" } ; 00026 char* Forward[64] = { "susume.\r", "<ALPHA VAL=start>.\r" } ; 00027 char* Stop[64] = { "tomare.\r", "<ALPHA VAL=stop>.\r" } ; 00028 char* Backward[64] = { "sagare.\r", "bakku.\r" } ; 00029 char* LeftTurn[64] = { "<ALPHA VAL=left>.\r", "sasetu.\r" } ; 00030 char* RightTurn[64] = { "raito.\r", "usetu.\r" } ; 00031 char* LeftBackward[64] = { "hidariusiro.\r", "usiro /hidari.\r" }; 00032 char* RightBackward[64] = { "migiusiro.\r", "usiro /migi.\r" }; 00033 char* LeftOblique[64] = { "naname/hidari.\r","hidari/naname.\r" }; 00034 char* RightOblique[64] = { "naname/migi.\r","migi/naname.\r" }; 00035 char* Acceleration[64] = { "hayaku.\r","supi-do/appu.\r" }; 00036 char* Deceleration[64] = { "osoku.\r","supi-do/daun.\r" }; 00037 00038 float speed=0; 00039 float Rdata=1; 00040 float Ldata=1; 00041 float threshold=0.2; 00042 S40kHz.period_us(25); // 40kHz 00043 S40kHz.pulsewidth_us(12.5); 00044 Light=0; 00045 j = count; 00046 00047 talk.Synthe("sumahode,ennbextudo'ka-o/ugoka'_su+koto'ga/dekima'_su.\r"); 00048 talk.Synthe("ta'xtu_chi+shite/ugoka'_shite+mi'te+kudasa'i.\r"); 00049 talk.Synthe("mata shabe'ttemo/je'_sucha-demo/ugokasema'_su.\r"); 00050 talk.Synthe("ma'zuwa buru-twu'-suni/setsuzo_kushimasho'-.\r"); 00051 00052 while (1) { 00053 if(bluetooth.readable()) { 00054 i=0; 00055 do { 00056 buf=bluetooth.getc(); 00057 moji[i++]=buf; 00058 } while(buf!='\0'); 00059 buf=moji[0]; 00060 } 00061 for(int i = 0; i <= 1; i++) { 00062 if (strcmp(LeftBackward[i],moji) == 0) buf='1'; 00063 if (strcmp(Backward[i],moji) == 0) buf='2'; 00064 if (strcmp(RightBackward[i],moji) == 0) buf='3'; 00065 if (strcmp(LeftTurn[i],moji) == 0) buf='4'; 00066 if (strcmp(Stop[i],moji) == 0) buf='5'; 00067 if (strcmp(RightTurn[i],moji) == 0) buf='6'; 00068 if (strcmp(LeftOblique[i],moji) == 0) buf='7'; 00069 if (strcmp(Forward[i],moji) == 0) buf='8'; 00070 if (strcmp(RightOblique[i],moji) == 0) buf='9'; 00071 if (strcmp(LightOn[i],moji) == 0) buf='+'; 00072 if (strcmp(LightOff[i],moji) == 0) buf='-'; 00073 if (strcmp(Acceleration[i],moji) == 0) buf='*'; 00074 if (strcmp(Deceleration[i],moji) == 0) buf='0'; 00075 } 00076 00077 if(Ain > threshold) { 00078 StopSignal=0; // Red LED ON 00079 if((buf>='4')){ 00080 buf='5'; 00081 IN1=1;IN2=1; 00082 if(onsei==1) { 00083 talk.Synthe("zennpo-ni sho-gai'butsuo/hakkennshima'_shita.\r"); 00084 talk.Synthe("ka'i_hi+shitekudasa'i.\r"); 00085 onsei=0; 00086 } 00087 } 00088 } else { 00089 StopSignal=1; // Red LED OFF 00090 onsei=1; 00091 } 00092 switch (buf){ 00093 case '1': // Left Backward 00094 IN1=1;IN2=0; 00095 Rdata=0.4+speed; Ldata=0.6+speed; 00096 Rin=Rdata; Lin=Ldata; 00097 talk.Synthe("hidariusiro.\r"); 00098 break; 00099 case '2': // Backward 00100 IN1=1;IN2=0; 00101 Rdata=0.5+speed; Ldata=0.5+speed; 00102 Rin=Rdata; Lin=Ldata; 00103 talk.Synthe("ushironi/sagarima'_su.\r"); 00104 break; 00105 case '3': // Right Backward 00106 IN1=1;IN2=0; 00107 Rdata=0.6+speed; Ldata=0.4+speed; 00108 Rin=Rdata; Lin=Ldata; 00109 talk.Synthe("migiusiro.\r"); 00110 break; 00111 case '4': // Left Turn 00112 IN1=0;IN2=1; 00113 Rdata=0.3+speed; Ldata=0.8+speed; 00114 Rin=Rdata; Lin=Ldata; 00115 talk.Synthe("sasetsu.\r"); 00116 break; 00117 case '5': // Stop 00118 IN1=1;IN2=1; 00119 break; 00120 case '6': // Right Turn 00121 IN1=0;IN2=1; 00122 Rdata=0.8+speed; Ldata=0.3+speed; 00123 Rin=Rdata; Lin=Ldata; 00124 talk.Synthe("usetsu.\r"); 00125 break; 00126 case '7': // Left Oblique 00127 IN1=0;IN2=1; 00128 Rdata=0.4+speed; Ldata=0.6+speed; 00129 Rin=Rdata; Lin=Ldata; 00130 talk.Synthe("hidarinana'me.\r"); 00131 break; 00132 case '8': // Forward 00133 IN1=0;IN2=1; 00134 Rdata=0.5+speed; Ldata=0.5+speed; 00135 Rin=Rdata; Lin=Ldata; 00136 talk.Synthe("zennshinn.\r"); 00137 break; 00138 case '9': // Right Oblique 00139 IN1=0;IN2=1; 00140 Rdata=0.6+speed; Ldata=0.4+speed; 00141 Rin=Rdata; Lin=Ldata; 00142 talk.Synthe("miginana'me.\r"); 00143 break; 00144 case '+': //Light On 00145 Light=1; 00146 talk.Synthe("#J\r"); 00147 talk.Synthe("ra'itoo/tennto-shima'_su.\r"); 00148 break; 00149 case '-': //Light Off 00150 Light=0; 00151 talk.Synthe("#J\r"); 00152 talk.Synthe("ra'itoo/keshima'_su.\r"); 00153 break; 00154 case '0': // Deceleration 00155 speed=speed+0.05; 00156 Rdata=Rdata+speed; Ldata=Ldata+speed; 00157 Rin=Rdata; Lin=Ldata; 00158 talk.Synthe("gennsoku.\r"); 00159 break; 00160 case '*': // Acceleration 00161 speed=speed-0.05; 00162 Rdata=Rdata+speed; Ldata=Ldata+speed; 00163 Rin=Rdata; Lin=Ldata; 00164 talk.Synthe("kasoku.\r"); 00165 break; 00166 default: 00167 j--; 00168 if( j == 0) { 00169 talk.Synthe(" .\r"); 00170 j = count; 00171 } 00172 break; 00173 } 00174 buf='X'; 00175 moji[0]=0; 00176 } 00177 }
Generated on Wed Jul 13 2022 17:54:14 by
1.7.2