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: LCD4884 MFRC522 eeprom mbed
main.cpp
00001 /*#include "mbed.h" 00002 00003 //------------------------------------ 00004 // Hyperterminal configuration 00005 // 9600 bauds, 8-bit data, no parity 00006 //------------------------------------ 00007 00008 Serial pc(SERIAL_TX, SERIAL_RX); 00009 00010 DigitalOut myled(LED1); 00011 00012 int main() { 00013 int i = 1; 00014 pc.printf("Hello World !\n"); 00015 while(1) { 00016 wait(1); 00017 pc.printf("This program runs since %d seconds.\n", i++); 00018 myled = !myled; 00019 } 00020 } 00021 */ 00022 00023 00024 #include "mbed.h" 00025 #include "MFRC522.h" 00026 #include "eeprom.h" 00027 #include "LCD4884.h" 00028 //KL25Z Pins for MFRC522 SPI interface 00029 #define SPI_MOSI PB_15 00030 #define SPI_MISO PB_14 00031 #define SPI_CLK PB_13 00032 #define SPI_CS PB_12 00033 // KL25Z Pin for MFRC522 reset 00034 #define MF_RESET PH_1 00035 // KL25Z Pins for Debug UART port 00036 #define UART_RX D0 00037 #define UART_TX D1 00038 00039 Serial device(D8,D2); 00040 DigitalIn plusbutton(PA_11); 00041 DigitalIn minusbutton(PA_12); 00042 uint16_t command[7]; 00043 uint16_t re_command[7]; 00044 uint16_t ch; 00045 int color ,clear ; 00046 char random[4][4]={"x0","x1","x2","x3"}; 00047 int num_random[4] ; 00048 int highb , lowb ; //Send Number of Bottle 00049 int total ; 00050 int t_score ; 00051 Serial pc(SERIAL_TX,SERIAL_RX); 00052 MFRC522 RFID(SPI_MOSI, SPI_MISO, SPI_CLK,SPI_CS, MF_RESET); 00053 EEPROM memory(D14,D15,0); 00054 AnalogIn LDR(PC_3); 00055 DigitalOut red(PA_1); 00056 DigitalOut green(PA_4); 00057 DigitalOut blue(PB_0); 00058 DigitalIn limitsw(PC_9); 00059 DigitalOut redled(D10); 00060 DigitalOut greenled(D9); 00061 DigitalIn rightbutton(D11); 00062 DigitalIn leftbutton(D12); 00063 DigitalOut ln1(PA_13); 00064 DigitalOut ln2(PA_14); 00065 DigitalOut Ena(PC_8); 00066 DigitalIn limitright(PC_10); 00067 DigitalIn limitcenter(PC_12); 00068 DigitalIn limitleft(PC_11); 00069 LCD4884 lcd; 00070 Timer t ; 00071 Timer t2 ; 00072 Timer t3 ; 00073 int16_t recieve ; 00074 int check; 00075 int counttran = 0 , countcolor = 0 ; 00076 float valuered,valueblue,valuegreen; 00077 00078 //MFRC522::MIFARE_Key key; 00079 class USER 00080 { 00081 public: 00082 char Name[20] ; 00083 char Surname[20] ; 00084 char StudentID[11] ; 00085 uint16_t point; 00086 int place ; 00087 USER(char name[],char surname[],char id[],int p) { 00088 for(int i=0; name[i]!='\0'; i++) { 00089 Name[i] = name[i]; 00090 } 00091 for(int i=0; surname[i]!='\0'; i++) { 00092 Surname[i] =surname[i]; 00093 } 00094 for(int i=0; id[i]!='\0'; i++) { 00095 StudentID[i] =id[i]; 00096 } 00097 place = p ; 00098 memory.read(place,recieve); 00099 wait_ms(2); 00100 point = recieve ; 00101 } 00102 int getPoint() { 00103 memory.read(place,recieve); 00104 wait_ms(2); 00105 point = recieve ; 00106 return point ; 00107 } 00108 void UpdatePoint(int16_t s) { 00109 memory.read(place,recieve); 00110 point = recieve ; 00111 s = point + s; 00112 point = s ; 00113 memory.write(place,(uint16_t)s); 00114 wait_ms(2); 00115 } 00116 void SetPoint() { 00117 memory.write(place,NULL); 00118 wait_ms(2); 00119 } 00120 }; 00121 00122 00123 void reverse(char *s) 00124 { 00125 char *j; 00126 int c; 00127 00128 j = s + strlen(s) - 1; 00129 while(s < j) { 00130 c = *s; 00131 *s++ = *j; 00132 *j-- = c; 00133 } 00134 } 00135 void itoa(int n, char s[]) 00136 { 00137 int i, sign; 00138 00139 if ((sign = n) < 0) /* record sign */ 00140 n = -n; /* make n positive */ 00141 i = 0; 00142 do { /* generate digits in reverse order */ 00143 s[i++] = n % 10 + '0'; /* get next digit */ 00144 } while ((n /= 10) > 0); /* delete it */ 00145 if (sign < 0) 00146 s[i++] = '-'; 00147 s[i] = '\0'; 00148 reverse(s); 00149 } 00150 void ShowUser(USER user) 00151 { 00152 char Sur[2] ; 00153 Sur[0] = user.Surname[0]; 00154 Sur[1] = '.'; 00155 char buff[50] ; 00156 itoa(user.point,buff); 00157 lcd.LCD_clear(); 00158 lcd.LCD_write_string(0,0,user.Name,0); 00159 lcd.LCD_write_string(55,0,Sur,0); 00160 lcd.LCD_write_string(0,2,user.StudentID,0); 00161 lcd.LCD_write_string(0,3,"Point : ",0); 00162 lcd.LCD_write_string(44,3,buff,0); //buff=point 00163 00164 } 00165 void motor() 00166 { 00167 00168 00169 00170 } 00171 void colorsensor(int &colors,int &clears) 00172 { 00173 char buff[40] ; 00174 char buff2[40] ; 00175 red = 1; 00176 blue = 1; 00177 green = 1 ; 00178 redled = 0 ; 00179 greenled = 1 ; 00180 //1=low 0=high 00181 // GREEN 00182 if(limitsw == 1) { 00183 sprintf(buff,"Clear: %d x2",counttran); 00184 lcd.LCD_write_string(0,2,buff,0); 00185 sprintf(buff2,"Color: %d x1",countcolor); 00186 lcd.LCD_write_string(0,3,buff2,0); 00187 t2.reset(); //30sec 00188 redled = 1 ; 00189 greenled = 0 ; 00190 //GReen 00191 red = 1; 00192 blue = 1; 00193 green = 0 ; 00194 wait(1); 00195 valuegreen = LDR.read(); 00196 valuegreen = valuegreen*10000; 00197 00198 // BLUE 00199 red = 1; 00200 blue = 0; 00201 green = 1 ; 00202 wait(1); 00203 valueblue = LDR.read(); 00204 valueblue = valueblue*10000; 00205 00206 // RED 00207 red = 0; 00208 blue = 1 ; 00209 green = 1 ; 00210 wait(1); 00211 valuered = LDR.read(); 00212 valuered = valuered*10000; 00213 00214 pc.printf("%d %d %d\n",limitleft.read(),limitright.read(),limitcenter.read()); 00215 pc.printf(" G = %f\n B = %f\nR = %f\n",valuegreen,valueblue,valuered); 00216 wait(1); 00217 if(valuegreen >= valuered && valuegreen >= valueblue && (valuered+valueblue)<=valuegreen ||valueblue >= valuered || valueblue >= valuegreen ) 00218 { 00219 pc.printf("\n color\n"); 00220 countcolor++ ; 00221 sprintf(buff2,"Color: %d x1",countcolor); 00222 lcd.LCD_write_string(0,3,buff2,0); 00223 do{ 00224 ln1 = 0 ; // ทวนเข็ม 00225 ln2 = 1 ; 00226 Ena = 1 ; 00227 00228 }while(limitleft == 0 ); 00229 pc.printf("checklimitleft"); 00230 ln1 = 1 ; 00231 ln2 = 0 ; 00232 Ena = 1 ; 00233 wait(1.5); 00234 00235 ln1 = 0 ; 00236 ln2 = 0 ; 00237 Ena = 0 ; 00238 pc.printf("color bottle\n %d",countcolor); 00239 00240 } 00241 else 00242 { 00243 if(valuegreen >300 ||valuegreen-valueblue > 80 || valueblue-valuegreen > 100 && valuered -((valuegreen+valueblue)/2)<170) 00244 { 00245 pc.printf("\ncolor\n"); 00246 00247 countcolor++ ; 00248 sprintf(buff2,"Color: %d x1",countcolor); 00249 lcd.LCD_write_string(0,3,buff2,0); 00250 do{ 00251 ln1 = 0 ; // ทวนเข็ม 00252 ln2 = 1 ; 00253 Ena = 1 ; 00254 00255 }while(limitleft == 0 ); 00256 pc.printf("checklimitleft2"); 00257 ln1 = 1 ; 00258 ln2 = 0 ; 00259 Ena = 1 ; 00260 wait(1.5); 00261 00262 ln1 = 0 ; 00263 ln2 = 0 ; 00264 Ena = 0 ; 00265 pc.printf("color bottle\n %d",countcolor); 00266 00267 00268 00269 } 00270 else if(valuegreen <300 ||valuegreen-valueblue < 80 || valueblue-valuegreen < 100 && valuered -((valuegreen+valueblue)/2)>170) 00271 { 00272 pc.printf("\nclear\n");} 00273 counttran++ ; 00274 00275 00276 sprintf(buff,"Clear: %d x2",counttran); 00277 lcd.LCD_write_string(0,2,buff,0); 00278 do{ 00279 ln1 = 1 ; //ตามเข็ม 00280 ln2 = 0 ; 00281 Ena = 1 ; 00282 00283 }while(limitright == 0 ); 00284 pc.printf("checklimitright"); 00285 ln1 = 0 ; 00286 ln2 = 1 ; 00287 Ena = 1 ; 00288 wait(1.5); 00289 00290 ln1 = 0 ; 00291 ln2 = 0 ; 00292 Ena = 0 ; 00293 00294 pc.printf("transparent bottle\n %d ",counttran); 00295 00296 } 00297 00298 00299 } 00300 int total ; 00301 total = countcolor + (counttran * 2); 00302 colors = countcolor ; 00303 clears = counttran ; 00304 sprintf(buff2,"total: %d ",total); 00305 lcd.LCD_write_string(0,4,buff2,0); 00306 00307 red = 1; 00308 blue = 1; 00309 green = 1 ; 00310 while(limitsw == 1) { 00311 00312 } 00313 t2.reset(); 00314 } 00315 00316 USER Jettanan("Jettanan","Homchanthanakul","57340500015",1); 00317 USER Nutthaya("Nutthaya","Hankla","57340500025",5); 00318 USER Kanokwan("Kanokwan","Toncheingsai","57340500001",9); 00319 char welcome[40] = {"Welcome to pae-za-leng"}; 00320 char please[40] = {"please touch your card"}; 00321 char selectstart[20] = {"start"}; 00322 char selectcancel[20] = {"cancel"}; 00323 00324 int main() 00325 { 00326 int check =0 ; 00327 red = 1; 00328 blue = 1; 00329 green = 1 ; 00330 uint8_t data,card[4]= {0}; 00331 pc.baud(115200); 00332 Nutthaya.UpdatePoint(1000); 00333 RFID.PCD_Reset(); 00334 wait(1.0); 00335 RFID.PCD_Init(); 00336 lcd.LCD_init(); 00337 lcd.backlight(OFF); 00338 while(1) {//e 00339 counttran = 0; 00340 countcolor = 0; 00341 lcd.backlight(ON); 00342 lcd.LCD_write_string(0,0,welcome,0); 00343 lcd.LCD_write_string(0,3,please,0); 00344 // Look for new cards // Select one of the cards 00345 if ( ! RFID.PICC_IsNewCardPresent() || ! RFID.PICC_ReadCardSerial()) { 00346 continue; 00347 } 00348 00349 // Print Card UID 00350 pc.printf("Card UID: "); 00351 for(int i=0; card[i]!='\0'; i++) { 00352 card[i] = 0; 00353 } 00354 for (uint8_t i = 0; RFID.uid.uidByte[i]!= '\0' ; i++) { 00355 card[i] = data = RFID.uid.uidByte[i] ; 00356 pc.printf(" %d",data); 00357 00358 } 00359 00360 00361 //////data card\\\\\\\ 00362 00363 if(card[0] == 106 && card[1] == 230 && card[2] == 38 && card[3] == 231) { 00364 pc.printf("\n Name : Jettanan H. \n Student's ID : 57340500015 \n point : %d ",Jettanan.getPoint()); 00365 ShowUser(Jettanan); 00366 } 00367 if(card[0] == 186 && card[1] == 151 && card[2] == 37 && card[3] == 231) { 00368 pc.printf("\n Name : Nutthaya H. \n Student's ID : 57340500025 \n point : %d ",Nutthaya.getPoint()); 00369 ShowUser(Nutthaya); 00370 } 00371 if(card[0] == 199 && card[1] == 230 && card[2] == 46 ) { 00372 pc.printf("\n Name : Kanokwan T. \n Student's ID : 57340500001 \n point : %d ",Kanokwan.getPoint()); 00373 ShowUser(Kanokwan); 00374 } 00375 lcd.LCD_write_string(55,5,selectstart,1); 00376 lcd.LCD_write_string(0,5,selectcancel,1); 00377 00378 pc.printf("\n\r"); 00379 00380 t.start(); 00381 t.reset(); 00382 while(t.read_ms()<10000) { 00383 //5 00384 if( rightbutton == 1 && leftbutton == 0) { 00385 //2 00386 greenled = 1; 00387 00388 00389 00390 while(rightbutton ==1) 00391 {wait(0.1);} 00392 00393 wait(0.5); 00394 lcd.LCD_clear(); 00395 00396 t2.start(); 00397 t2.reset(); 00398 lcd.LCD_write_string(0,0,"insert bottle",0); 00399 //lcd.LCD_clear(); 00400 while(t2.read_ms()<30000) { 00401 //1 00402 check = 1 ; 00403 color = 0; 00404 clear = 0; 00405 colorsensor(color,clear); 00406 t3.start(); 00407 t3.reset(); 00408 while(t3.read_ms()<500) { 00409 lcd.LCD_write_string(44,5,"Submit",1); 00410 if(rightbutton == 1) { 00411 while(rightbutton ==1) 00412 {wait(0.1);} 00413 wait(0.5); 00414 goto LAND ; 00415 } 00416 } 00417 lcd.LCD_write_string(44,5," ",0); 00418 greenled = 0 ; 00419 }//1 00420 00421 00422 }//2 00423 else if(leftbutton == 1){break;} 00424 00425 }//5 00426 LAND : 00427 while(rightbutton ==1) 00428 {wait(0.1);} 00429 wait(0.5); 00430 lcd.LCD_clear(); 00431 while(check == 1) { 00432 00433 lcd.LCD_write_string(10,0,"Do you want",0); 00434 lcd.LCD_write_string(14,1,"to play a",0); 00435 lcd.LCD_write_string(20,3,"GAME ?",0); 00436 lcd.LCD_write_string(5,5,"No",0); 00437 lcd.LCD_write_string(40,5,"Yes",0); 00438 if(rightbutton == 1 && leftbutton == 0) { 00439 //3 00440 while(rightbutton ==1) 00441 {wait(0.1);} 00442 00443 lcd.LCD_write_string(0,3,"join the GAME!",0); 00444 wait(1); 00445 /*Extend*/ 00446 lcd.backlight(ON); 00447 lcd.LCD_init(); 00448 total = countcolor + (counttran*2); 00449 color = countcolor ; 00450 clear = counttran ; 00451 highb = color/256 ; 00452 lowb = color - (highb*256); 00453 command[3] = lowb ; 00454 command[2] = highb ; 00455 highb = clear/256 ; 00456 lowb = clear - (highb*256); 00457 command[5] = lowb ; 00458 command[4] = highb ; 00459 command[0] = 0x42 ; 00460 command[1] = 0x52 ; 00461 command[6] = 0x4D ; 00462 00463 for(int i=0;i<7;i++) 00464 { 00465 wait(0.1); 00466 device.putc(command[i]); 00467 pc.printf("%x\n",command[i]); 00468 00469 } 00470 00471 //After allow to play game 00472 if(total<=1) 00473 { 00474 lcd.LCD_clear(); 00475 lcd.LCD_write_string(0,2,"Sorry you don't",0); 00476 lcd.LCD_write_string(0,3,"have any point",0); 00477 wait(3); 00478 uint16_t sim ; 00479 sim = total ; 00480 if(card[0] == 106 && card[1] == 230 && card[2] == 38 && card[3] == 231) { 00481 Jettanan.UpdatePoint(sim); 00482 wait(1); 00483 ShowUser(Jettanan); 00484 } 00485 if(card[0] == 186 && card[1] == 151 && card[2] == 37 && card[3] == 231) { 00486 Nutthaya.UpdatePoint(sim); 00487 wait(1); 00488 ShowUser(Nutthaya); 00489 } 00490 if(card[0] == 199 && card[1] == 230 && card[2] == 46 ) { 00491 Kanokwan.UpdatePoint(sim); 00492 wait(1); 00493 ShowUser(Kanokwan); 00494 } 00495 wait(3); 00496 goto EXIT; 00497 } 00498 00499 int totalsim; 00500 uint16_t credits; 00501 totalsim = total; 00502 credits = 0; 00503 pc.printf("Game mode"); 00504 lcd.LCD_clear(); 00505 00506 while(1)//select credits 00507 { 00508 00509 lcd.LCD_write_string(0,0,"total P :",0); 00510 lcd.LCD_write_string(10,1,"credits :",0); 00511 lcd.LCD_write_string(0,3,"2 Point = 1 Credits",0); 00512 char buff[4]; 00513 sprintf(buff,"%d",totalsim); 00514 lcd.LCD_write_string(67,0,buff,0); 00515 00516 char buff2[4]; 00517 sprintf(buff2,"%d",credits); 00518 lcd.LCD_write_string(67,1,buff2,1); 00519 if(plusbutton ==1) 00520 { 00521 while(plusbutton==1) 00522 {wait(0.2);} 00523 if((totalsim-2)>=0) 00524 { 00525 credits = credits +1 ; 00526 totalsim = totalsim - 2; 00527 pc.printf("credits + 1"); 00528 lcd.LCD_clear(); 00529 } 00530 } 00531 if(minusbutton ==1) 00532 { 00533 while(minusbutton==1) 00534 {wait(0.2);} 00535 if((credits-1)>=0) 00536 { 00537 credits = credits - 1 ; 00538 totalsim = totalsim + 2; 00539 pc.printf("credits - 1"); 00540 lcd.LCD_clear(); 00541 } 00542 } 00543 if(leftbutton ==1) 00544 { 00545 uint16_t pointsim ; 00546 pointsim = total ; 00547 if(card[0] == 106 && card[1] == 230 && card[2] == 38 && card[3] == 231) { 00548 Jettanan.UpdatePoint(pointsim); 00549 wait(1); 00550 pc.printf("point sim = %d\n",pointsim); 00551 ShowUser(Jettanan); 00552 } 00553 if(card[0] == 186 && card[1] == 151 && card[2] == 37 && card[3] == 231) { 00554 Nutthaya.UpdatePoint(pointsim); 00555 wait(1); 00556 pc.printf("point sim = %d\n",pointsim); 00557 ShowUser(Nutthaya); 00558 } 00559 if(card[0] == 199 && card[1] == 230 && card[2] == 46 ) { 00560 Kanokwan.UpdatePoint(pointsim); 00561 wait(1); 00562 pc.printf("point sim = %d\n",pointsim); 00563 ShowUser(Kanokwan); 00564 } 00565 wait(3); 00566 pc.printf("left"); 00567 goto LEFT ; 00568 } 00569 if(rightbutton ==1) 00570 { 00571 if(credits ==0) 00572 { 00573 pc.printf("continue"); 00574 continue; 00575 } 00576 else if(credits >=1) 00577 { 00578 command[0]=0x42; 00579 command[1]=0x50; 00580 command[2]=0x00; 00581 command[3]=0x00; 00582 command[4]=0x00; 00583 command[5]=credits; 00584 command[6]=0x4D; 00585 for(int i=0;i<7;i++) 00586 { 00587 wait(0.1); 00588 device.putc(command[i]); 00589 pc.printf("%x\n",command[i]); 00590 00591 } 00592 uint16_t simm ; 00593 simm = total-(credits*2) ; 00594 if(card[0] == 106 && card[1] == 230 && card[2] == 38 && card[3] == 231) { 00595 Jettanan.UpdatePoint(simm); 00596 wait(0.3); 00597 ShowUser(Jettanan); 00598 } 00599 if(card[0] == 186 && card[1] == 151 && card[2] == 37 && card[3] == 231) { 00600 Nutthaya.UpdatePoint(simm); 00601 wait(0.3); 00602 ShowUser(Nutthaya); 00603 } 00604 if(card[0] == 199 && card[1] == 230 && card[2] == 46 ) { 00605 Kanokwan.UpdatePoint(simm); 00606 wait(0.3); 00607 ShowUser(Kanokwan); 00608 } 00609 pc.printf("left"); 00610 break; 00611 } 00612 } 00613 00614 }//select credits 00615 lcd.LCD_clear(); 00616 for(int w=0;w<credits;w++) 00617 { 00618 lcd.LCD_clear(); 00619 lcd.LCD_write_string(0,0,"Credits:",0); 00620 char buff[4]; 00621 sprintf(buff,"%d",credits-w); 00622 for(int i=0;i<7;i++) 00623 { 00624 re_command[i]=device.getc(); 00625 pc.printf("%x\n",re_command[i]); 00626 } 00627 if(re_command[0]==0x42 && re_command[1]==0x45 && re_command[6]==0x4D) 00628 { 00629 pc.printf("command not found"); 00630 break; 00631 } 00632 lcd.LCD_write_string(46,0,buff,0); 00633 lcd.LCD_write_string(58,0,"1 :",0); 00634 lcd.LCD_write_string(66,0,"??",0); 00635 lcd.LCD_write_string(58,1,"2 :",0); 00636 lcd.LCD_write_string(66,1,"??",0); 00637 lcd.LCD_write_string(58,2,"3 :",0); 00638 lcd.LCD_write_string(66,2,"??",0); 00639 lcd.LCD_write_string(58,3,"4 :",0); 00640 lcd.LCD_write_string(66,3,"??",0); 00641 lcd.LCD_write_string(0,4,"Pick up ball",0); 00642 lcd.LCD_write_string(0,5,"Dropto Gripper",0); 00643 ch = device.getc(); 00644 lcd.LCD_write_string(0,4," ",0); 00645 lcd.LCD_write_string(0,5," ",0); 00646 ch = device.getc(); 00647 if(ch == 0x53) 00648 { 00649 lcd.LCD_write_string(58,0,"1 :",0); 00650 lcd.LCD_write_string(66,0,random[re_command[2]],0); 00651 lcd.LCD_write_string(58,1,"2 :",0); 00652 lcd.LCD_write_string(66,1,random[re_command[3]],0); 00653 lcd.LCD_write_string(58,2,"3 :",0); 00654 lcd.LCD_write_string(66,2,random[re_command[4]],0); 00655 lcd.LCD_write_string(58,3,"4 :",0); 00656 lcd.LCD_write_string(66,3,random[re_command[5]],0); 00657 lcd.LCD_write_string(0,4," ",0); 00658 lcd.LCD_write_string(0,5," ",0); 00659 pc.printf("Start"); 00660 } 00661 ch = device.getc(); 00662 char checkc[4]; 00663 //char random[4][4]={"x0","x1","x2","x3"}; 00664 if(ch == 1) 00665 { 00666 lcd.LCD_write_string(58,0,"1 :",1); 00667 lcd.LCD_write_string(66,0,random[re_command[2]],1); 00668 sprintf(checkc,"%s",random[re_command[2]]) ; 00669 00670 } 00671 else if(ch == 2) 00672 { 00673 lcd.LCD_write_string(58,1,"2 :",1); 00674 lcd.LCD_write_string(66,1,random[re_command[3]],1); 00675 sprintf(checkc,"%s",random[re_command[3]]) ; 00676 } 00677 else if(ch == 3) 00678 { 00679 lcd.LCD_write_string(58,2,"3 :",1); 00680 lcd.LCD_write_string(66,2,random[re_command[4]],1); 00681 sprintf(checkc,"%s",random[re_command[4]]) ; 00682 } 00683 else if(ch == 4) 00684 { 00685 lcd.LCD_write_string(58,3,"4 :",1); 00686 lcd.LCD_write_string(66,3,random[re_command[5]],1); 00687 sprintf(checkc,"%s",random[re_command[5]]) ; 00688 } 00689 if(checkc[1] == '0') 00690 { 00691 t_score = t_score+0; 00692 pc.printf("t_t"); 00693 } 00694 else if(checkc[1] == '1') 00695 { 00696 t_score = t_score+2; 00697 pc.printf("t_t"); 00698 } 00699 else if(checkc[1] == '2') 00700 { 00701 t_score = t_score+4; 00702 pc.printf("t_t"); 00703 } 00704 else if(checkc[1] == '3') 00705 { 00706 t_score = t_score+6; 00707 pc.printf("t_t"); 00708 } 00709 uint16_t gg; 00710 gg = device.getc(); 00711 } 00712 00713 lcd.LCD_clear(); 00714 lcd.LCD_write_string(0,0,"Total Score :",0); 00715 char buff3[6]; 00716 sprintf(buff3,"%d",t_score); 00717 lcd.LCD_write_string(0,1,buff3,1); 00718 LEFT : 00719 00720 if(card[0] == 106 && card[1] == 230 && card[2] == 38 && card[3] == 231) { 00721 Jettanan.UpdatePoint(t_score); 00722 wait(0.3); 00723 ShowUser(Jettanan); 00724 } 00725 if(card[0] == 186 && card[1] == 151 && card[2] == 37 && card[3] == 231) { 00726 Nutthaya.UpdatePoint(t_score); 00727 wait(0.3); 00728 ShowUser(Nutthaya); 00729 } 00730 if(card[0] == 199 && card[1] == 230 && card[2] == 46 ) { 00731 Kanokwan.UpdatePoint(t_score); 00732 wait(0.3); 00733 ShowUser(Kanokwan); 00734 } 00735 wait(3); 00736 lcd.LCD_clear(); 00737 /*End Extend*/ 00738 EXIT : 00739 lcd.LCD_clear(); 00740 break; 00741 }//3 00742 else if(leftbutton == 1) { 00743 //4 00744 while(leftbutton ==1) 00745 {wait(0.1);} 00746 total = countcolor + (counttran*2); 00747 color = countcolor ; 00748 clear = counttran ; 00749 highb = color/256 ; 00750 lowb = color - (highb*256); 00751 command[3] = lowb ; 00752 command[2] = highb ; 00753 highb = clear/256 ; 00754 lowb = clear - (highb*256); 00755 command[5] = lowb ; 00756 command[4] = highb ; 00757 command[0] = 0x42 ; 00758 command[1] = 0x52 ; 00759 command[6] = 0x4D ; 00760 00761 for(int i=0;i<7;i++) 00762 { 00763 wait(0.1); 00764 device.putc(command[i]); 00765 pc.printf("%x\n",command[i]); 00766 00767 } 00768 uint16_t sim2 ; 00769 sim2 = total; 00770 if(card[0] == 106 && card[1] == 230 && card[2] == 38 && card[3] == 231) { 00771 Jettanan.UpdatePoint(sim2); 00772 wait(1); 00773 ShowUser(Jettanan); 00774 } 00775 if(card[0] == 186 && card[1] == 151 && card[2] == 37 && card[3] == 231) { 00776 Nutthaya.UpdatePoint(sim2); 00777 wait(1); 00778 ShowUser(Nutthaya); 00779 } 00780 if(card[0] == 199 && card[1] == 230 && card[2] == 46 ) { 00781 Kanokwan.UpdatePoint(sim2); 00782 wait(1); 00783 ShowUser(Kanokwan); 00784 } 00785 wait(3); 00786 card[0] = 0; 00787 card[1] = 0; 00788 card[2] = 0; 00789 card[3] = 0; 00790 lcd.LCD_clear(); 00791 break; 00792 }//4 00793 } 00794 00795 00796 lcd.LCD_clear(); 00797 check = 0; 00798 }//e 00799 }
Generated on Sun Jul 24 2022 07:58:09 by
1.7.2