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
Fork of Proj by
main.cpp
00001 #include "mbed.h" 00002 00003 Serial duino(PA_11, PA_12); 00004 Serial pc(USBTX, USBRX); 00005 DigitalIn btn(USER_BUTTON); 00006 DigitalIn btn1(); 00007 DigitalIn btn2(D5); 00008 Timer timer; 00009 uint8_t state_new=0; 00010 uint8_t state_menu=0; 00011 uint8_t state_show=0; 00012 uint8_t state_exit =0; 00013 uint8_t data; 00014 int last[3] = {0,0,0}; 00015 00016 int lis[60] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30}; 00017 // 0-50 00018 00019 void func() 00020 { //send 1 12 0b 00110 00021 int x[9]={0x06,0x40,0x00,0x00,0x00,0x00,0x13,0x10,0x14}; 00022 int y[8]={23,12,14,16,9,4,0,0}; 00023 int ansx[8]; 00024 int ansy[8]; 00025 int k = 0; 00026 for (int j =0 ; j< 8;j++) 00027 { ansx[j]= x[j]; 00028 duino.putc(ansx[j]); 00029 pc.printf("one time\n"); 00030 wait(0.1); 00031 } 00032 for (int j =0 ; j< 8;j++) 00033 { ansy[j]= y[j]; 00034 duino.putc(ansy[j]); 00035 pc.printf("two time\n"); 00036 wait(0.1); 00037 } 00038 k++; 00039 if(k>4){ 00040 k=0; 00041 } 00042 00043 00044 } 00045 00046 00047 void chackmape(){ // 00048 if (timer.read() > 1) { 00049 pc.printf("Writingccccc!\n\r"); 00050 00051 duino.putc(lis[23]); 00052 00053 timer.reset(); 00054 } 00055 if (duino.readable()) 00056 { 00057 pc.printf("Ponnnnnnnn!\n\r"); 00058 00059 pc.printf("recieving %c\n",duino.getc()); 00060 } 00061 } 00062 00063 void Win(){ //ชนะ 00064 if (timer.read() > 1) { 00065 pc.printf("Writingmnm!\n\r"); 00066 duino.putc(lis[0]); 00067 duino.putc(lis[1]); 00068 duino.putc(lis[2]); 00069 timer.reset(); 00070 } 00071 if (duino.readable()) 00072 { 00073 pc.printf("recieving %c",duino.getc()); 00074 } 00075 } 00076 00077 void Lose(){ //แพ้ 00078 00079 if (timer.read() > 1) { 00080 pc.printf("Writing!\n\r"); 00081 duino.putc(lis[3]); 00082 duino.putc(lis[4]); 00083 duino.putc(lis[5]); 00084 duino.putc(lis[6]); 00085 timer.reset(); 00086 } 00087 if (duino.readable()) 00088 { 00089 pc.printf("recieving %c",duino.getc()); 00090 } 00091 00092 } 00093 00094 00095 void number(){ //นับเวลา 00096 if (timer.read() > 1) { 00097 pc.printf("Writing!\n\r"); 00098 duino.putc(lis[7]); //9 00099 duino.putc(lis[8]); //8 00100 duino.putc(lis[9]); //7 00101 duino.putc(lis[10]);//6 00102 duino.putc(lis[11]);//5 00103 duino.putc(lis[12]);//4 00104 duino.putc(lis[13]);//3 00105 duino.putc(lis[14]);//2 00106 duino.putc(lis[15]);//1 00107 duino.putc(lis[16]);//0 00108 00109 timer.reset(); 00110 } 00111 if (duino.readable()){ 00112 pc.printf("recieving %c",duino.getc()); 00113 } 00114 00115 } 00116 00117 00118 void correct(){ //เช็คถูก 00119 if (timer.read() > 1) { 00120 pc.printf("Writing!\n\r"); 00121 duino.putc(lis[18]); 00122 timer.reset(); 00123 } 00124 if (duino.readable()){ 00125 pc.printf("recieving %c",duino.getc()); 00126 } 00127 00128 } 00129 00130 void error(){ // 00131 if (timer.read() > 1) { 00132 pc.printf("Writing!\n\r"); 00133 duino.putc(lis[19]); 00134 timer.reset(); 00135 } 00136 if (duino.readable()){ 00137 pc.printf("recieving %c",duino.getc()); 00138 } 00139 00140 } 00141 void heart(){ //ลงค่าเสร็จ 00142 if (timer.read() > 1) { 00143 pc.printf("Writing!\n\r"); 00144 00145 00146 duino.putc(lis[20]); 00147 00148 00149 timer.reset(); 00150 } 00151 if (duino.readable()){ 00152 pc.printf("recieving %c",duino.getc()); 00153 } 00154 00155 } 00156 void woman(){ //ตัวหลัก 00157 if (timer.read() > 1) { 00158 pc.printf("Writing!\n\r"); 00159 00160 00161 duino.putc(lis[21]); 00162 00163 00164 timer.reset(); 00165 } 00166 if (duino.readable()){ 00167 pc.printf("recieving %c",duino.getc()); 00168 } 00169 00170 } 00171 void von(){ //หมุน 00172 if (timer.read() > 1) { 00173 pc.printf("Writing!\n\r"); 00174 00175 00176 duino.putc(lis[22]); 00177 00178 00179 timer.reset(); 00180 } 00181 if (duino.readable()){ 00182 pc.printf("recieving %c",duino.getc()); 00183 } 00184 00185 } 00186 00187 00188 int main() { 00189 00190 00191 00192 pc.baud(9600); 00193 duino.baud(9600); 00194 pc.printf("Starting...\n\r"); 00195 00196 timer.start(); 00197 while (1) { 00198 if (btn == 9) 00199 { 00200 Win(); 00201 00202 } 00203 00204 if (btn == 9) 00205 { 00206 Lose(); 00207 00208 } 00209 if (btn == 9) 00210 { 00211 number(); 00212 00213 } 00214 00215 if (btn == 9) //True 00216 { 00217 correct(); 00218 } 00219 00220 if (btn == 9) //error 00221 { 00222 error(); 00223 00224 } 00225 if (btn == 9) 00226 { 00227 heart(); 00228 } 00229 00230 if (btn == 9) 00231 { 00232 woman(); 00233 } 00234 if (btn == 9) 00235 { 00236 von(); 00237 } 00238 if (btn == 0) 00239 { 00240 00241 chackmape(); 00242 } 00243 00244 wait(0.4); 00245 00246 if(state_show == 0) { 00247 pc.printf("************\n"); 00248 pc.printf(" Menu \n"); 00249 pc.printf("1.Menu1\n"); 00250 00251 state_show =1; 00252 } 00253 if(pc.readable()) { 00254 data = pc.getc(); 00255 pc.printf("\n"); 00256 state_show =0; 00257 state_exit =0; 00258 switch(data) { 00259 case '1': 00260 do { 00261 if(state_menu == 0) { 00262 pc.printf("number 1-9\n"); 00263 00264 state_menu = 1; 00265 } 00266 if(pc.readable()) 00267 { 00268 data = pc.getc(); 00269 pc.printf("\n"); 00270 state_menu=0; 00271 switch(data) { 00272 wait(0.5); 00273 case '1': 00274 duino.putc(lis[15]);//1 00275 break; 00276 00277 case '2': 00278 duino.putc(lis[14]);//2 00279 break; 00280 case '3': 00281 duino.putc(lis[13]);//3 00282 break; 00283 case '4': 00284 duino.putc(lis[12]);//4 00285 break; 00286 case '5': 00287 duino.putc(lis[11]);//5 00288 break; 00289 case '6': 00290 duino.putc(lis[10]);//6 00291 break; 00292 case '7': 00293 duino.putc(lis[9]);//7 00294 break; 00295 case '8': 00296 duino.putc(lis[8]);//8 00297 break; 00298 case '9': 00299 duino.putc(lis[7]);//9 00300 00301 break; 00302 case 'H': 00303 duino.putc(lis[17]);//happy 00304 00305 break; 00306 00307 00308 default: 00309 pc.printf("plz select a or s\n"); 00310 pc.printf("\n\n"); 00311 break; 00312 } 00313 } 00314 } while(state_exit ==0); 00315 pc.printf("\n"); 00316 break; 00317 00318 00319 00320 } 00321 } 00322 } 00323 }
Generated on Wed Jul 13 2022 07:00:21 by
1.7.2
