Coursework
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 /** 00002 *.....Kory Hamill 00003 *.....IOT Smart Electronics Coursework 00004 *.....Acknowlegements Libary Makers 00005 *.....18689004 00006 */ 00007 /** 00008 * Section of code to bring in the #includes 00009 * TO DO : 00010 * Debounce Issue 00011 * Second Button Press B menu take from switch of A to own switch 00012 00013 */ 00014 #include "mbed.h" 00015 //#include "Joystick.h" Not used in project 00016 #include "N5110.h" 00017 #include "hcsr04.h" 00018 #include "Piezo.h" 00019 #include "string" 00020 #include "array" 00021 #include <iostream> 00022 #include <numeric> 00023 00024 using namespace std; 00025 00026 /** 00027 *...This Section of the code is used to bring in volatile Varible's, These can be wrote to throught the code. 00028 *...The Varibles are used to track button press's on the board. 00029 */ 00030 volatile int g_ButtonAPress; 00031 volatile int g_ButtonBPress; 00032 volatile int LoopCountScan1; 00033 volatile int LoopCountScan2; 00034 volatile int LoopCountScan3; 00035 volatile int LoopCountScan4; 00036 volatile int LoopCountScan5; 00037 volatile int LoopCountScan6; 00038 volatile int g_buttonA_flag = 0; 00039 volatile int g_buttonB_flag = 0; 00040 volatile int g_buttonX_flag = 0; 00041 volatile int g_buttonY_flag = 0; 00042 volatile int g_buttonStart_flag = 0; 00043 volatile int g_buttonBack_flag = 0; 00044 volatile int g_buttonLeft_flag = 0; 00045 volatile int g_buttonRight_flag = 0; 00046 volatile int wallTotal; 00047 volatile int boxTotal; 00048 volatile int cartonTotal; 00049 volatile int triangleTotal; 00050 /** 00051 *..Bring in 5 arrays of 5 for each of the 5 required scans. 00052 *..array Ref starts at 0, 00053 */ 00054 volatile int Scan1[5]; 00055 /* no longer required 00056 volatile int Scan2[5]; 00057 volatile int Scan3[5]; 00058 volatile int Scan4[5]; 00059 volatile int Scan5[5]; 00060 volatile int wall[5]; 00061 */ 00062 /** 00063 *... Section of code to assign names to IO pins on the K64f 00064 */ 00065 InterruptIn buttonA(PTB9); 00066 InterruptIn buttonB(PTD0); 00067 InterruptIn buttonX(PTC17); 00068 InterruptIn buttonY(PTC12); 00069 InterruptIn buttonStart(PTC5); 00070 InterruptIn buttonBack(PTB19); 00071 InterruptIn buttonLeft(PTB18); 00072 InterruptIn buttonRight(PTB3); 00073 //Joystick joystick(PTB10,PTB11,PTC16); Not used in project 00074 HCSR04 sensor(D14, D15); 00075 Piezo Buzzer(PTC10); 00076 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); 00077 00078 /** 00079 *...For used with the LCD Screen. rows,cols 00080 */ 00081 int sprite[8][5] = { 00082 { 0,0,1,0,0 }, 00083 { 0,1,1,1,0 }, 00084 { 0,0,1,0,0 }, 00085 { 0,1,1,1,0 }, 00086 { 1,1,1,1,1 }, 00087 { 1,1,1,1,1 }, 00088 { 1,1,0,1,1 }, 00089 { 1,1,0,1,1 }, 00090 }; 00091 /** 00092 *...Section for starting the board and seeting up interrupt routines 00093 *...Along with other functions to be called later 00094 */ 00095 void init_K64F(); // Start K64fBoard 00096 void buttonA_isr(); // Button A interrupt service routine 00097 void buttonB_isr(); // Button B interrupt service routine 00098 void buttonX_isr(); // Button X interrupt service routine 00099 void buttonY_isr(); // Button Y interrupt service routine 00100 void buttonStart_isr(); // Button Start interrupt service routine 00101 void buttonBack_isr(); // Button Back interrupt service routine 00102 void buttonLeft_isr(); // Button Left interrupt service routine 00103 void buttonRight_isr(); // Button Right interrupt service routine 00104 /** 00105 *..Void set up to use the scan 00106 */ 00107 void inputScan1(); 00108 void inputScan2(); 00109 void inputScan3(); 00110 void inputScan4(); 00111 void inputScan5(); 00112 void inputScan6(); 00113 /** 00114 *..Decision Void used to print what we have. 00115 */ 00116 void wallDecision(); 00117 void boxDecision(); 00118 void cartonDecision(); 00119 void triangleDecision(); 00120 int NoContinueExit(); 00121 int buttonCountA(); 00122 int buttonCountB(); 00123 00124 void printShape(); /**<Prints the shape*/ 00125 00126 00127 00128 00129 00130 EventQueue queue; /**< Required to get around issues with printing onto LCD and the Printf */ 00131 00132 00133 /** Code which was never used 00134 * 00135 *.. was for initial learning of C++ 00136 //volatile int g_buttonA_counter = 0; // Global counter 00137 //Test function after research C++ lanuage 05/01/22 00138 int cube(int num){ 00139 return num*num; 00140 }; 00141 // Menu Items 00142 int page1; 00143 int page2; 00144 int page3; 00145 string Listitem1 = "Game"; // 00146 string Listitem2 = "Measure"; // 00147 string Listitem3 = "Detect"; // 00148 / Test of the interup an operating the buzzer this kills the board 00149 void buzzme(){ 00150 Buzzer.play(200,120); 00151 wait_ms(5); 00152 Buzzer.play(200,120);; 00153 } 00154 int Scan1[5]; 00155 int Scan2[5]; 00156 int Scan1Input(){; 00157 Scan1[0] = sensor.distance(); 00158 Scan1[1] = sensor.distance();; 00159 Scan1[2] = sensor.distance();; 00160 Scan1[3] = sensor.distance();; 00161 Scan1[4] = sensor.distance();; 00162 return Scan1[0,1,2,3,4];} 00163 //void returnme(){ 00164 //int num; 00165 // return num*num; 00166 // }; 00167 */ 00168 /* 00169 bool Equal(int ar1[],int ar2[], int n, int m){ 00170 if(n!=m) 00171 return false; 00172 sort(ar1,ar1 +n); 00173 sort(ar2,ar2 +m); 00174 for (int i=0;i<n; i++) 00175 if(ar1[i]!=ar2[i]) 00176 return false; 00177 return true; 00178 }*/ 00179 /* Problems with this and Being exact and repeatable 00180 bool MatchMade(int arr1[], int arr2[], int n, int m) 00181 { 00182 // If lengths of array are not equal means 00183 // array are not equal 00184 if (n != m) 00185 return false; 00186 00187 // Sort both arrays 00188 sort(arr1, arr1 + n); 00189 sort(arr2, arr2 + m); 00190 00191 // Linearly compare elements 00192 for (int i = 0; i < n; i++) 00193 if (arr1[i] != arr2[i]) 00194 return false; 00195 00196 00197 // If all elements were same. 00198 return true; 00199 */ 00200 00201 int main() 00202 { 00203 00204 00205 /** 00206 *.. Intialise joystick and Lcd 00207 */ 00208 // joystick.init(); not used in project 00209 lcd.init(); 00210 lcd.setContrast(0.5); 00211 /** 00212 *.. Issues were found with the LCd and printf while using interrupts, to get around 00213 *.. this issue these queue's to the event thread were added. 00214 */ 00215 Thread eventThread; 00216 eventThread.start(callback(&queue, &EventQueue::dispatch_forever)); 00217 buttonA.rise(queue.event(&buttonA_isr)); 00218 buttonB.rise(queue.event(&buttonB_isr)); 00219 buttonX.rise(queue.event(&buttonX_isr)); 00220 buttonY.rise(queue.event(&buttonY_isr)); 00221 buttonStart.rise(queue.event(&buttonStart_isr)); 00222 buttonBack.rise(queue.event(&buttonBack_isr)); 00223 buttonLeft.rise(queue.event(&buttonLeft_isr)); 00224 buttonRight.rise(queue.event(&buttonRight_isr)); 00225 /** 00226 *..Buttons were connected to IO pins which required a pull down resistor to be active. 00227 */ 00228 buttonA.mode(PullDown); 00229 buttonB.mode(PullDown); 00230 buttonX.mode(PullDown); 00231 buttonY.mode(PullDown); 00232 buttonStart.mode(PullDown); 00233 buttonBack.mode(PullDown); 00234 buttonLeft.mode(PullDown); 00235 buttonRight.mode(PullDown); 00236 00237 /** 00238 *.. Section of code not used in main program. 00239 * 00240 Buzzer.period(10.0f); 00241 //Buzzer.pulsewidth(1); 00242 Test Struct after research 05/01/22 00243 struct ObjectDefine{ 00244 int qwer; 00245 float Distance; 00246 char te; 00247 double dubs; 00248 string namestruct; 00249 // string ; 00250 }; 00251 // Test Class 06/01/22 00252 class myClass{ 00253 public: 00254 string nameclass ; 00255 double dubss; 00256 int inty; 00257 }; 00258 myClass Class1; 00259 Class1.nameclass ="firstclass"; 00260 ObjectDefine Object1; 00261 Object1.qwer = 12; 00262 Object1.Distance = 34; 00263 Object1.te = 'A'; 00264 Object1.dubs = 23; 00265 Object1.namestruct = "name"; 00266 */ 00267 00268 /* 00269 int ar1[]= {2,3,4,5}; 00270 int ar2[] = {2,3,4,5}; 00271 int n = sizeof(ar1); 00272 int m = sizeof(ar2); 00273 if(Equal(ar1,ar2,n,m)){ 00274 printf("TRUEEEEEEEEEEEEEEEEEEE\n");} 00275 else {printf("Falseeeeeeeeeeeeeeeeeeeeeeeeeeeddddddddd\n");} 00276 00277 00278 00279 00280 */ 00281 00282 00283 00284 00285 00286 printf("I SHOULD HAVE BEEN PRINTED !!!!!"); 00287 00288 while(1) { 00289 00290 /** 00291 *.. It was found Cout was not working as expected. 00292 cout << "Test value collection"; 00293 Scan1Input(); 00294 00295 cout << Scan1[0];cout <<"/n"; 00296 cout << Scan1[1];"/n"; 00297 cout << Scan1[2];"/n"; 00298 cout << Scan1[3];"/n"; 00299 cout << Scan1[4];"/n"; 00300 cout << Scan1[5];"/n"; 00301 cout << Scan1[6];"/n"; 00302 cout << Scan1[7];"/n"; 00303 cout << Scan1[8];"/n"; 00304 cout << Scan1[9];"/n"; 00305 *//* Removing from coolterm printout 00306 printf("Debug : LoopCount1 : %i\n",LoopCountScan1); 00307 printf("Debug : LoopCount2 : %i\n",LoopCountScan2); 00308 printf("Debug : LoopCount3 : %i\n",LoopCountScan3); 00309 printf("Debug : LoopCount4 : %i\n",LoopCountScan4); 00310 printf("Debug : LoopCount5 : %i\n",LoopCountScan5); 00311 printf("press count = %i\n",g_ButtonAPress); 00312 */ 00313 printf("Scan1 1 : %d cm\n", Scan1[0]); 00314 printf("Scan1 2 : %d cm\n", Scan1[1]); 00315 printf("Scan1 3 : %d cm\n", Scan1[2]); 00316 printf("Scan1 4 : %d cm\n", Scan1[3]); 00317 printf("Scan1 5 : %d cm\n", Scan1[4]); 00318 /* NO longer Reuired Section 00319 printf("Scan2 1 : %d cm\n", Scan2[0]); 00320 printf("Scan2 2 : %d cm\n", Scan2[1]); 00321 printf("Scan2 3 : %d cm\n", Scan2[2]); 00322 printf("Scan2 4 : %d cm\n", Scan2[3]); 00323 printf("Scan2 5 : %d cm\n", Scan2[4]); 00324 printf("Scan3 1 : %d cm\n", Scan3[0]); 00325 printf("Scan3 2 : %d cm\n", Scan3[1]); 00326 printf("Scan3 3 : %d cm\n", Scan3[2]); 00327 printf("Scan3 4 : %d cm\n", Scan3[3]); 00328 printf("Scan3 5 : %d cm\n", Scan3[4]); 00329 printf("Scan4 1 : %d cm\n", Scan4[0]); 00330 printf("Scan4 2 : %d cm\n", Scan4[1]); 00331 printf("Scan4 3 : %d cm\n", Scan4[2]); 00332 printf("Scan4 4 : %d cm\n", Scan4[3]); 00333 printf("Scan4 5 : %d cm\n", Scan4[4]); 00334 printf("Scan5 1 : %d cm\n", Scan5[0]); 00335 printf("Scan5 2 : %d cm\n", Scan5[1]); 00336 printf("Scan5 3 : %d cm\n", Scan5[2]); 00337 printf("Scan5 4 : %d cm\n", Scan5[3]); 00338 printf("Scan5 5 : %d cm\n", Scan5[4]); 00339 */ 00340 printf("I always Get printed \n"); 00341 // cout << Scan1[2]; 00342 // cout << Scan1[6]; 00343 printf("I Should Be printed always \n"); 00344 /** 00345 *..Code section on Comparing data Cout was causing issue 00346 * 00347 if (Scan1[1] > Scan1[2]){ 00348 cout <<'+'; 00349 }else if (Scan1[1]=Scan1[2]){ 00350 cout <<'=';} 00351 else { 00352 cout <<'-';} 00353 if (Scan1[2] > Scan1[3]){ 00354 cout <<'+'; 00355 }else if (Scan1[2]=Scan1[3]){ 00356 cout <<'=';} 00357 else { 00358 cout <<'-';} 00359 00360 if (Scan1[3] > Scan1[4]){ 00361 cout <<'+'; 00362 }else if (Scan1[3]=Scan1[4]){ 00363 cout <<'=';} 00364 else { 00365 cout <<'-';} 00366 if (Scan1[4] > Scan1[5]){ 00367 cout <<'+'; 00368 }else if (Scan1[4]=Scan1[5]){ 00369 cout <<'=';} 00370 else { 00371 cout <<'-';} 00372 if (Scan1[5] > Scan1[6]){ 00373 cout <<'+'; 00374 }else if (Scan1[5]=Scan1[6]){ 00375 cout <<'=';} 00376 else { 00377 cout <<'-';} 00378 if (Scan1[6] > Scan1[7]){ 00379 cout <<'+'; 00380 }else if (Scan1[6]=Scan1[7]){ 00381 cout <<'=';} 00382 else { 00383 cout <<'-';} 00384 if (Scan1[7] > Scan1[8]){ 00385 cout <<'+'; 00386 }else if (Scan1[7]=Scan1[8]){ 00387 cout <<'=';} 00388 else { 00389 cout <<'-';} 00390 00391 if (Scan1[8] > Scan1[9]){ 00392 cout <<'+'; 00393 }else if (Scan1[8]=Scan1[9]){ 00394 cout <<'=';} 00395 else { 00396 cout <<'-';} 00397 if (Scan1[9] > Scan1[10]){ 00398 cout <<'+'; 00399 }else if (Scan1[9]=Scan1[10]){ 00400 cout <<'=';} 00401 else { 00402 cout <<'-';} 00403 */ 00404 00405 ///////////////////////////////////////////////////////////////////////////////////////////////////// 00406 /** 00407 *..Initial state when starting the Board. 00408 */ 00409 switch(g_ButtonAPress) { 00410 default: 00411 lcd.clear(); 00412 lcd.printString("Main Menu",0,0); 00413 lcd.drawLine(0,10,80,10,2); 00414 lcd.printString("Press A",0,2); 00415 lcd.printString("New Scan",0,3); 00416 lcd.printString("Press B",0,4); 00417 lcd.printString("Decicde",0,5); 00418 LoopCountScan1 =0; 00419 LoopCountScan2 =0; 00420 LoopCountScan3 =0; 00421 LoopCountScan4 =0; 00422 LoopCountScan5 =0; 00423 LoopCountScan6 =0; 00424 00425 00426 00427 /* Code Section No longer required 00428 * 00429 00430 for(int i=0; i<5; i++){ 00431 00432 printf("hello Scan: %i The value of : %i \n",i, Scan1[i]); 00433 if (Scan1[i]>95){ 00434 Decide[i]= '+'; 00435 printf("no wall%c/n",Decide[i]);} 00436 else if (Scan1[i]<85){ 00437 Decide[i]= '-'; 00438 printf("OBJECT ABOUT%c/n",Decide[i]);} 00439 else if (Scan1[i]>85<95){ 00440 Decide[i]= '='; 00441 printf("No Object %c/n",Decide[i]);} 00442 } 00443 */ 00444 00445 00446 00447 /** IF Statement to decide on shape to draw 00448 *.. This section of code compares the each array element with the one proceding it and makes a logical decision if higher lower or equal. 00449 */ 00450 /* 00451 if (Scan1[0] > Scan1[1]) 00452 { 00453 printf("+"); 00454 Decide[0]= 'x'; 00455 printf( "chosen 1 %c\n",Decide[0]); 00456 } 00457 else if (Scan1[0] == Scan1[1]) 00458 { 00459 printf("="); 00460 Decide[0]='='; 00461 printf( "chosen2 %c\n",Decide[0]); 00462 } 00463 else if (Scan1[0] < Scan1[1]) 00464 { 00465 printf("-"); 00466 Decide[0]='-'; 00467 printf( "chosen3 %c\n",Decide[0]); 00468 } 00469 if (Scan1[1] > Scan1[2]) 00470 { 00471 printf("+"); 00472 Decide[1]= 'x'; 00473 printf( "chosen 1 %c\n",Decide[1]); 00474 } 00475 else if (Scan1[1] == Scan1[2]) 00476 { 00477 printf("="); 00478 Decide[1]='='; 00479 printf( "chosen2 %c\n",Decide[1]); 00480 } 00481 else if (Scan1[1] < Scan1[2]) 00482 { 00483 printf("-"); 00484 Decide[1]='-'; 00485 printf( "chosen3 %c\n",Decide[1]); 00486 } 00487 00488 if (Scan1[2] > Scan1[3]) 00489 { 00490 printf("+"); 00491 Decide[2]= 'x'; 00492 printf( "chosen 1 %c\n",Decide[2]); 00493 } 00494 else if (Scan1[2] == Scan1[3]) 00495 { 00496 printf("="); 00497 Decide[2]='='; 00498 printf( "chosen2 %c\n",Decide[2]); 00499 } 00500 else if (Scan1[2] < Scan1[3]) 00501 { 00502 printf("-"); 00503 Decide[2]='-'; 00504 printf( "chosen3 %c\n",Decide[2]); 00505 } 00506 if (Scan1[3] > Scan1[4]) 00507 { 00508 printf("+"); 00509 Decide[3]= 'x'; 00510 printf( "chosen 1 %c\n",Decide[3]); 00511 } 00512 else if (Scan1[3] == Scan1[4]) 00513 { 00514 printf("="); 00515 Decide[3]='='; 00516 printf( "chosen2 %c\n",Decide[3]); 00517 } 00518 else if (Scan1[3] < Scan1[4]) 00519 { 00520 printf("-"); 00521 Decide[3]='-'; 00522 printf( "chosen3 %c\n",Decide[3]); 00523 } 00524 00525 if (Scan2[0] > Scan2[1]) 00526 { 00527 printf("+"); 00528 Decide2[0]= 'x'; 00529 printf( "chosen 1 %c\n",Decide2[0]); 00530 } 00531 else if (Scan2[0] == Scan2[1]) 00532 { 00533 printf("="); 00534 Decide2[0]='='; 00535 printf( "chosen2 %c\n",Decide2[0]); 00536 } 00537 else if (Scan2[0] < Scan2[1]) 00538 { 00539 printf("-"); 00540 Decide2[0]='-'; 00541 printf( "chosen3 %c\n",Decide2[0]); 00542 } 00543 if (Scan2[1] > Scan2[2]) 00544 { 00545 printf("+"); 00546 Decide2[1]= 'x'; 00547 printf( "chosen 1 %c\n",Decide2[1]); 00548 } 00549 else if (Scan2[1] == Scan2[2]) 00550 { 00551 printf("="); 00552 Decide2[1]='='; 00553 printf( "chosen2 %c\n",Decide2[1]); 00554 } 00555 else if (Scan2[1] < Scan2[2]) 00556 { 00557 printf("-"); 00558 Decide2[1]='-'; 00559 printf( "chosen3 %c\n",Decide2[1]); 00560 } 00561 00562 if (Scan2[2] > Scan2[3]) 00563 { 00564 printf("+"); 00565 Decide2[2]= 'x'; 00566 printf( "chosen 1 %c\n",Decide2[2]); 00567 } 00568 else if (Scan2[2] == Scan2[3]) 00569 { 00570 printf("="); 00571 Decide2[2]='='; 00572 printf( "chosen2 %c\n",Decide2[2]); 00573 } 00574 else if (Scan2[2] < Scan2[3]) 00575 { 00576 printf("-"); 00577 Decide2[2]='-'; 00578 printf( "chosen3 %c\n",Decide2[2]); 00579 } 00580 if (Scan2[3] > Scan2[4]) 00581 { 00582 printf("+"); 00583 Decide2[3]= 'x'; 00584 printf( "chosen 1 %c\n",Decide2[3]); 00585 } 00586 else if (Scan2[3] == Scan2[4]) 00587 { 00588 printf("="); 00589 Decide2[3]='='; 00590 printf( "chosen2 %c\n",Decide2[3]); 00591 } 00592 else if (Scan2[3] < Scan2[4]) 00593 { 00594 printf("-"); 00595 Decide2[3]='-'; 00596 printf( "chosen3 %c\n",Decide2[3]); 00597 } 00598 00599 if (Scan3[0] > Scan3[1]) 00600 { 00601 printf("+"); 00602 Decide3[0]= 'x'; 00603 printf( "chosen 1 %c\n",Decide3[0]); 00604 } 00605 else if (Scan3[0] == Scan3[1]) 00606 { 00607 printf("="); 00608 Decide3[0]='='; 00609 printf( "chosen2 %c\n",Decide3[0]); 00610 } 00611 else if (Scan3[0] < Scan3[1]) 00612 { 00613 printf("-"); 00614 Decide3[0]='-'; 00615 printf( "chosen3 %c\n",Decide3[0]); 00616 } 00617 if (Scan3[1] > Scan3[2]) 00618 { 00619 printf("+"); 00620 Decide3[1]= 'x'; 00621 printf( "chosen 1 %c\n",Decide3[1]); 00622 } 00623 else if (Scan3[1] == Scan3[2]) 00624 { 00625 printf("="); 00626 Decide3[1]='='; 00627 printf( "chosen2 %c\n",Decide3[1]); 00628 } 00629 else if (Scan3[1] < Scan3[2]) 00630 { 00631 printf("-"); 00632 Decide3[1]='-'; 00633 printf( "chosen3 %c\n",Decide3[1]); 00634 } 00635 00636 if (Scan3[2] > Scan3[3]) 00637 { 00638 printf("+"); 00639 Decide3[2]= 'x'; 00640 printf( "chosen 1 %c\n",Decide3[2]); 00641 } 00642 else if (Scan3[2] == Scan3[3]) 00643 { 00644 printf("="); 00645 Decide3[2]='='; 00646 printf( "chosen2 %c\n",Decide3[2]); 00647 } 00648 else if (Scan3[2] < Scan3[3]) 00649 { 00650 printf("-"); 00651 Decide3[2]='-'; 00652 printf( "chosen3 %c\n",Decide3[2]); 00653 } 00654 if (Scan3[3] > Scan3[4]) 00655 { 00656 printf("+"); 00657 Decide3[3]= 'x'; 00658 printf( "chosen 1 %c\n",Decide3[3]); 00659 } 00660 else if (Scan3[3] == Scan3[4]) 00661 { 00662 printf("="); 00663 Decide3[3]='='; 00664 printf( "chosen2 %c\n",Decide3[3]); 00665 } 00666 else if (Scan3[3] < Scan3[4]) 00667 { 00668 printf("-"); 00669 Decide3[3]='-'; 00670 printf( "chosen3 %c\n",Decide3[3]); 00671 } 00672 00673 if (Scan4[0] > Scan4[1]) 00674 { 00675 printf("+"); 00676 Decide4[0]= 'x'; 00677 printf( "chosen 1 %c\n",Decide4[0]); 00678 } 00679 else if (Scan4[0] == Scan4[1]) 00680 { 00681 printf("="); 00682 Decide4[0]='='; 00683 printf( "chosen2 %c\n",Decide4[0]); 00684 } 00685 else if (Scan4[0] < Scan4[1]) 00686 { 00687 printf("-"); 00688 Decide4[0]='-'; 00689 printf( "chosen3 %c\n",Decide4[0]); 00690 } 00691 if (Scan4[1] > Scan4[2]) 00692 { 00693 printf("+"); 00694 Decide4[1]= 'x'; 00695 printf( "chosen 1 %c\n",Decide4[1]); 00696 } 00697 else if (Scan4[1] == Scan4[2]) 00698 { 00699 printf("="); 00700 Decide4[1]='='; 00701 printf( "chosen2 %c\n",Decide4[1]); 00702 } 00703 else if (Scan4[1] < Scan4[2]) 00704 { 00705 printf("-"); 00706 Decide4[1]='-'; 00707 printf( "chosen3 %c\n",Decide4[1]); 00708 } 00709 00710 if (Scan4[2] > Scan4[3]) 00711 { 00712 printf("+"); 00713 Decide4[2]= 'x'; 00714 printf( "chosen 1 %c\n",Decide4[2]); 00715 } 00716 else if (Scan4[2] == Scan4[3]) 00717 { 00718 printf("="); 00719 Decide4[2]='='; 00720 printf( "chosen2 %c\n",Decide4[2]); 00721 } 00722 else if (Scan4[2] < Scan4[3]) 00723 { 00724 printf("-"); 00725 Decide4[2]='-'; 00726 printf( "chosen3 %c\n",Decide4[2]); 00727 } 00728 if (Scan4[3] > Scan4[4]) 00729 { 00730 printf("+"); 00731 Decide4[3]= 'x'; 00732 printf( "chosen 1 %c\n",Decide4[3]); 00733 } 00734 else if (Scan4[3] == Scan4[4]) 00735 { 00736 printf("="); 00737 Decide4[3]='='; 00738 printf( "chosen2 %c\n",Decide4[3]); 00739 } 00740 else if (Scan4[3] < Scan4[4]) 00741 { 00742 printf("-"); 00743 Decide4[3]='-'; 00744 printf( "chosen3 %c\n",Decide4[3]); 00745 } 00746 if (Scan5[0] > Scan5[1]) 00747 { 00748 printf("+"); 00749 Decide5[0]= 'x'; 00750 printf( "chosen 1 %c\n",Decide5[0]); 00751 } 00752 else if (Scan5[0] == Scan5[1]) 00753 { 00754 printf("="); 00755 Decide5[0]='='; 00756 printf( "chosen2 %c\n",Decide5[0]); 00757 } 00758 else if (Scan5[0] < Scan5[1]) 00759 { 00760 printf("-"); 00761 Decide5[0]='-'; 00762 printf( "chosen3 %c\n",Decide5[0]); 00763 } 00764 if (Scan5[1] > Scan5[2]) 00765 { 00766 printf("+"); 00767 Decide5[1]= 'x'; 00768 printf( "chosen 1 %c\n",Decide5[1]); 00769 } 00770 else if (Scan5[1] == Scan5[2]) 00771 { 00772 printf("="); 00773 Decide5[1]='='; 00774 printf( "chosen2 %c\n",Decide5[1]); 00775 } 00776 else if (Scan5[1] < Scan5[2]) 00777 { 00778 printf("-"); 00779 Decide5[1]='-'; 00780 printf( "chosen3 %c\n",Decide5[1]); 00781 } 00782 00783 if (Scan5[2] > Scan5[3]) 00784 { 00785 printf("+"); 00786 Decide5[2]= 'x'; 00787 printf( "chosen 1 %c\n",Decide5[2]); 00788 } 00789 else if (Scan5[2] == Scan5[3]) 00790 { 00791 printf("="); 00792 Decide5[2]='='; 00793 printf( "chosen2 %c\n",Decide5[2]); 00794 } 00795 else if (Scan5[2] < Scan5[3]) 00796 { 00797 printf("-"); 00798 Decide5[2]='-'; 00799 printf( "chosen3 %c\n",Decide5[2]); 00800 } 00801 if (Scan5[3] > Scan5[4]) 00802 { 00803 printf("+"); 00804 Decide5[3]= 'x'; 00805 printf( "chosen 1 %c\n",Decide5[3]); 00806 } 00807 else if (Scan5[3] == Scan5[4]) 00808 { 00809 printf("="); 00810 Decide5[3]='='; 00811 printf( "chosen2 %c\n",Decide5[3]); 00812 } 00813 else if (Scan5[3] < Scan5[4]) 00814 { 00815 printf("-"); 00816 Decide5[3]='-'; 00817 printf( "chosen3 %c\n",Decide5[3]); 00818 } */ 00819 00820 lcd.refresh(); 00821 wait_ms(50); 00822 00823 break; 00824 00825 ////////////////////////////////////////////////////////////////////////////////////////////////// 00826 /** 00827 *.. When Button A is pressed this section of code is ran to collect data points of the object. 00828 *..Scanning takes marks the LCD with locationof points which data has been collected for. 00829 */ 00830 case 1: 00831 g_ButtonAPress =1; 00832 /* 00833 *..Section used for power saving, if the user has not continued after 5 scans 00834 */ 00835 if(LoopCountScan1==100) { 00836 g_ButtonAPress=0; 00837 LoopCountScan1=0; 00838 break; 00839 } else; 00840 inputScan1(); 00841 break; 00842 /* 00843 wait_ms(5); // required to stop Black screen issue} 00844 inputScan2(); 00845 wait_ms(5); // required to stop Black screen issue} 00846 inputScan3(); 00847 00848 wait_ms(5); // required to stop Black screen issue} 00849 inputScan4(); 00850 00851 wait_ms(5); 00852 inputScan5(); 00853 00854 00855 00856 g_ButtonAPress=0; 00857 */ 00858 00859 //////////////////////////////////////////////////////////////////////////// 00860 case 2: 00861 g_ButtonAPress= 2; 00862 if(LoopCountScan2==100) { 00863 g_ButtonAPress=0; 00864 LoopCountScan2=0; 00865 break; 00866 } else; 00867 /*int secondScan[10]; 00868 00869 secondScan[5] = sensor.distance(); 00870 printf("Distance : %d cm", secondScan[5]); 00871 lcd.clear(); 00872 lcd.printString("2nd Scan up down",0,0); 00873 lcd.drawLine(0,10,80,10,2); */ 00874 inputScan2(); 00875 break; 00876 //////////////////////////////////////////////////////////////////// 00877 case 3: 00878 g_ButtonAPress= 3; 00879 if(LoopCountScan3==100) { 00880 g_ButtonAPress=0; 00881 LoopCountScan3=0; 00882 break; 00883 } else; 00884 /* lcd.clear(); 00885 lcd.printString("Menu 3",0,0); 00886 int us = sensor.distance(); 00887 printf("Distance : %d cm",us); 00888 lcd.refresh(); 00889 wait_ms(50); //required to stop Black screen issue*/ 00890 inputScan3(); 00891 break; 00892 00893 ///////////////////////////////////////////////////////////////////////// 00894 00895 case 4: 00896 g_ButtonAPress= 4; 00897 if(LoopCountScan4==100) { 00898 g_ButtonAPress=0; 00899 LoopCountScan4=0; 00900 break; 00901 } else; 00902 /* lcd.clear(); 00903 lcd.printString("Menu 3",0,0); 00904 int us = sensor.distance(); 00905 printf("Distance : %d cm",us); 00906 lcd.refresh(); 00907 wait_ms(50); //required to stop Black screen issue*/ 00908 inputScan4(); 00909 break; 00910 /////////////////////////////////////////////////////////////////// 00911 case 5: 00912 g_ButtonAPress= 5; 00913 if(LoopCountScan5==100) { 00914 g_ButtonAPress=0; 00915 LoopCountScan5=0; 00916 break; 00917 } else; 00918 /* lcd.clear(); 00919 lcd.printString("Menu 3",0,0); 00920 int us = sensor.distance(); 00921 printf("Distance : %d cm",us); 00922 lcd.refresh(); 00923 wait_ms(50); //required to stop Black screen issue*/ 00924 inputScan5(); 00925 break; 00926 00927 00928 00929 ///////////////////////////////////////////////////////////////// 00930 00931 00932 case 6: 00933 g_ButtonAPress=6; 00934 if(LoopCountScan6==20) { 00935 g_ButtonAPress=0; 00936 LoopCountScan6=0; 00937 break; 00938 } else; 00939 00940 inputScan6(); 00941 break; 00942 00943 /* 00944 int button_counter; 00945 if (g_buttonA_flag){ 00946 button_counter = button_counter +1; 00947 //case (test) 00948 g_buttonA_flag = 0; // if it has, clear the flag 00949 00950 // send message over serial port - can observe in CoolTerm etc. 00951 printf("Button A pressed %f\n", button_counter); 00952 } 00953 if (g_buttonB_flag){ 00954 g_buttonB_flag = 0; // if it has, clear the flag 00955 00956 // send message over serial port - can observe in CoolTerm etc. 00957 printf("Button B pressed\n"); 00958 } 00959 if (g_buttonX_flag){ 00960 g_buttonX_flag = 0; // if it has, clear the flag 00961 // swap direction when button has been pressed 00962 // (could just use ! but want this to be explicit to aid understanding) 00963 if (direction == UP) { 00964 direction = DOWN; 00965 } 00966 else { 00967 direction = UP; 00968 } 00969 00970 // send message over serial port - can observe in CoolTerm etc. 00971 printf("Button X pressed\n"); 00972 lcd.clear(); 00973 lcd.printString("Button Pressed!",0,0); 00974 lcd.refresh(); 00975 wait(1); 00976 } 00977 if (g_buttonY_flag){ 00978 g_buttonY_flag = 0; // if it has, clear the flag 00979 00980 // send message over serial port - can observe in CoolTerm etc. 00981 printf("Button Y pressed\n"); 00982 } 00983 Buzzer.play(200,120); 00984 wait_ms(5); 00985 Buzzer.play(200,120); 00986 long distanced = sensor.distance(); 00987 if (distanced >= 400 || distanced <= 2) 00988 { 00989 printf("Out of range"); 00990 //Calling dummy function 05/01/22 00991 int answer = cube(2); 00992 printf("%f\n",answer); 00993 wait(1.0); 00994 } 00995 else 00996 { 00997 printf("Distance : %d cm",distanced); 00998 wait(1.0); // 1 sec 00999 } 01000 lcd.drawCircle(WIDTH/2,HEIGHT/2,distanced,FILL_BLACK); 01001 //lcd.refresh must be used to update the lcd Display 01002 lcd.refresh(); 01003 wait(5.0); 01004 //these are default settings so not strictly needed 01005 lcd.normalMode(); // normal colour mode 01006 lcd.setBrightness(0.5); // put LED backlight on 50% 01007 lcd.clear(); 01008 lcd.printString("Hello, World!",0,0); 01009 Vector2D coord = joystick.get_coord(); 01010 lcd.refresh(); 01011 printf("Coord = %f,%f\n",coord.x,coord.y); 01012 char buffer[14]; 01013 Vector2D mapped_coord = joystick.get_mapped_coord(); 01014 printf("Mapped coord = %f,%f\n",mapped_coord.x,mapped_coord.y); 01015 01016 int length = sprintf(buffer,"T = %2f",coord.x); 01017 //it is important the format specifier ensures the length will fit in the buffer 01018 if (length <= 14) // if string will fit on display (assuming printing at x=0) 01019 lcd.printString(buffer,0,1); // display on screen 01020 lcd.refresh(); 01021 lcd.clear(); 01022 //times by 50 to try get the point moving across screen 01023 float x50 = mapped_coord.x*5; 01024 float y50 = mapped_coord.y*8; 01025 //to see what the values are 01026 printf(" *50 = %f,%f\n",x50,y50); 01027 //example of how to draw circles 01028 lcd.printChar('o',WIDTH/2,HEIGHT/2); 01029 lcd.refresh(); 01030 float mag = joystick.get_mag(); 01031 float angle = joystick.get_angle(); 01032 printf("Mag = %f Angle = %f\n",mag,angle); 01033 Direction d = joystick.get_direction(); 01034 printf("Direction = %i\n",d); 01035 if (joystick.button_pressed() ) { 01036 printf("Button Pressed\n"); 01037 wait(5); 01038 } 01039 01040 } 01041 } 01042 */ 01043 } 01044 } 01045 } 01046 int buttonCountA() 01047 { 01048 g_ButtonAPress++; 01049 if (g_ButtonAPress>5) { 01050 g_ButtonAPress= 0; 01051 } 01052 return g_ButtonAPress; 01053 } 01054 int buttonCountB() 01055 { 01056 g_ButtonBPress++; 01057 if (g_ButtonBPress>3) { 01058 g_ButtonBPress= 0; 01059 } 01060 return g_ButtonBPress; 01061 } 01062 int NoContinueExitScan1() 01063 { 01064 LoopCountScan1++; 01065 if (LoopCountScan1>100) { 01066 LoopCountScan1= 0; 01067 } 01068 return LoopCountScan1; 01069 } 01070 int NoContinueExitScan2() 01071 { 01072 LoopCountScan2++; 01073 if (LoopCountScan2>100) { 01074 LoopCountScan2= 0; 01075 } 01076 return LoopCountScan2; 01077 } 01078 int NoContinueExitScan3() 01079 { 01080 LoopCountScan3++; 01081 if (LoopCountScan3>100) { 01082 LoopCountScan3= 0; 01083 } 01084 return LoopCountScan3; 01085 } 01086 int NoContinueExitScan4() 01087 { 01088 LoopCountScan4++; 01089 if (LoopCountScan4>100) { 01090 LoopCountScan4= 0; 01091 } 01092 return LoopCountScan4; 01093 } 01094 int NoContinueExitScan5() 01095 { 01096 LoopCountScan5++; 01097 if (LoopCountScan5>100) { 01098 LoopCountScan5= 0; 01099 } 01100 return LoopCountScan5; 01101 } 01102 int NoContinueExitScan6() 01103 { 01104 LoopCountScan6++; 01105 if (LoopCountScan6>100) { 01106 LoopCountScan6= 0; 01107 } 01108 return LoopCountScan6; 01109 } 01110 01111 01112 //Button A event-triggered interrupt 01113 void buttonA_isr() 01114 { 01115 01116 long distanced = sensor.distance(); 01117 buttonCountA(); 01118 01119 01120 01121 g_buttonA_flag = 1; // set flag in ISR 01122 01123 printf("press count = %i\n",g_ButtonAPress); 01124 01125 // lcd.clear(); 01126 //lcd.printString("Button A Pressed",0,0); 01127 01128 // lcd.refresh(); // set flag in ISR 01129 } 01130 01131 01132 //Button B event-triggered interrupt 01133 void buttonB_isr() 01134 { 01135 buttonCountB(); 01136 g_buttonB_flag = 1; // set flag in ISR 01137 lcd.clear(); 01138 g_ButtonAPress = 6; // This is is a work around due to time constraints 01139 lcd.printString("Button B Pressed",0,0); 01140 01141 lcd.refresh(); // set flag in ISR 01142 printf("press count = %i\n",g_ButtonBPress); 01143 } 01144 //Button X event-triggered interrupt 01145 void buttonX_isr() 01146 { 01147 g_buttonX_flag = 1; // set flag in ISR 01148 lcd.clear(); 01149 lcd.printString("Button X Pressed",0,0); 01150 lcd.refresh(); // set flag in ISR 01151 } 01152 //Button Y event-triggered interrupt 01153 void buttonY_isr() 01154 { 01155 g_buttonY_flag = 1; // set flag in ISR 01156 lcd.clear(); 01157 lcd.printString("Button Y Pressed",0,0); 01158 lcd.refresh(); // set flag in ISR 01159 } 01160 //Button Start event-triggered interrupt 01161 void buttonStart_isr() 01162 { 01163 g_buttonStart_flag = 1; // set flag in ISR 01164 lcd.clear(); 01165 ///////////////////////////////////////////////// 01166 01167 /* 01168 * For loop required to assign array values to that of the scan value 01169 */ /* not required due to repeatablity issues 01170 int arr1[5] ; 01171 for(int i=0; i<5; i++){ 01172 arr1[i] =Scan1[i];} 01173 int arr2[] = { 90, 90, 90, 90, 90 }; 01174 int n = sizeof(arr1) / sizeof(int); 01175 int m = sizeof(arr2) / sizeof(int); 01176 */ 01177 01178 // if(MatchMade(arr1, arr2, n, m)) 01179 // printf("You are a wall"); 01180 // else 01181 // printf("Not THis Object"); ////////////////////////////////// 01182 01183 01184 lcd.printString("Button Start Pressed",0,0); 01185 lcd.refresh(); // set flag in ISR 01186 01187 } 01188 //Button Back event-triggered interrupt 01189 void buttonBack_isr() 01190 { 01191 g_buttonBack_flag = 1; // set flag in ISR 01192 lcd.clear(); 01193 lcd.printString("Button Back Pressed",0,0); 01194 lcd.refresh(); // set flag in ISR 01195 } 01196 //Button Left event-triggered interrupt 01197 void buttonLeft_isr() 01198 { 01199 g_buttonLeft_flag = 1; // set flag in ISR 01200 lcd.clear(); 01201 lcd.printString("Button Left Pressed",0,0); 01202 lcd.refresh(); // set flag in ISR 01203 } 01204 //Button Right event-triggered interrupt 01205 void buttonRight_isr() 01206 { 01207 g_buttonRight_flag = 1; // set flag in ISR 01208 lcd.clear(); 01209 lcd.printString("Button Right Pressed",0,0); 01210 lcd.refresh(); // set flag in ISR 01211 } 01212 /** 01213 *..Void for 1st scan 01214 **/ 01215 void inputScan1() 01216 { 01217 lcd.clear(); 01218 lcd.printString("First Scan",0,0); 01219 lcd.refresh(); 01220 NoContinueExitScan1(); 01221 01222 Buzzer.play(300,120); 01223 lcd.printString("X",0,1); 01224 lcd.refresh(); 01225 Scan1[0] = sensor.distance(); 01226 wait_ms(5); 01227 /* NO Longer Required Section 01228 Buzzer.play(200,120); lcd.printString("X",0,2);lcd.refresh(); Scan1[1] = sensor.distance(); 01229 wait_ms(5); 01230 Buzzer.play(200,120); lcd.printString("X",0,3);lcd.refresh(); Scan1[2] = sensor.distance(); 01231 wait_ms(5); 01232 Buzzer.play(200,120); lcd.printString("X",0,4);lcd.refresh(); Scan1[3] = sensor.distance();; 01233 wait_ms(5); 01234 Buzzer.play(200,120); lcd.printString("X",0,5);lcd.refresh(); Scan1[4] = sensor.distance();; 01235 wait_ms(5); */ 01236 lcd.printString("Scan 1 Done",0,0); 01237 lcd.refresh(); 01238 } 01239 /** 01240 *..Void for 2nd scan 01241 **/ 01242 void inputScan2() 01243 { 01244 lcd.clear(); 01245 lcd.printString("Second Scan",0,0); 01246 lcd.refresh(); 01247 NoContinueExitScan2(); 01248 lcd.printString("X",0,1); //No longer Required Line,lcd.printString("X",0,2),lcd.printString("X",0,3),lcd.printString("X",0,4),lcd.printString("X",0,5); lcd.refresh(); 01249 Buzzer.play(300,120); 01250 lcd.printString("X",15,1); 01251 lcd.refresh(); 01252 Scan1[1] = sensor.distance(); 01253 wait_ms(5);/* 01254 Buzzer.play(200,120); lcd.printString("X",15,2);lcd.refresh(); Scan2[1] = sensor.distance(); 01255 wait_ms(5); 01256 Buzzer.play(200,120); lcd.printString("X",15,3);lcd.refresh(); Scan2[2] = sensor.distance(); 01257 wait_ms(5); 01258 Buzzer.play(200,120); lcd.printString("X",15,4);lcd.refresh(); Scan2[3] = sensor.distance(); 01259 wait_ms(5); 01260 Buzzer.play(200,120); lcd.printString("X",15,5);lcd.refresh(); Scan2[4] = sensor.distance();*/ 01261 lcd.printString("Scan 2 Done",0,0); 01262 lcd.refresh(); 01263 01264 } 01265 /** 01266 *..Void for 3rd scan 01267 **/ 01268 void inputScan3() 01269 { 01270 lcd.clear(); 01271 lcd.printString("Third Scan",0,0); 01272 lcd.refresh(); 01273 NoContinueExitScan3(); 01274 lcd.printString("X",0,1);//No Longer required line,lcd.printString("X",0,2),lcd.printString("X",0,3),lcd.printString("X",0,4),lcd.printString("X",0,5); lcd.refresh(); 01275 lcd.printString("X",15,1);//No Longer required line,lcd.printString("X",15,2),lcd.printString("X",15,3),lcd.printString("X",15,4),lcd.printString("X",15,5); lcd.refresh(); 01276 Buzzer.play(300,120); 01277 lcd.printString("X",30,1); 01278 lcd.refresh(); 01279 Scan1[2] = sensor.distance(); 01280 wait_ms(5);/* 01281 Buzzer.play(200,120); lcd.printString("X",30,2);lcd.refresh(); Scan3[1] = sensor.distance(); 01282 wait_ms(5); 01283 Buzzer.play(200,120); lcd.printString("X",30,3);lcd.refresh(); Scan3[2] = sensor.distance(); 01284 wait_ms(5); 01285 Buzzer.play(200,120); lcd.printString("X",30,4);lcd.refresh(); Scan3[3] = sensor.distance(); 01286 wait_ms(5); 01287 Buzzer.play(200,120); lcd.printString("X",30,5);lcd.refresh(); Scan3[4] = sensor.distance(); */ 01288 lcd.printString("Scan 3 Done",0,0); 01289 lcd.refresh(); 01290 } 01291 /** 01292 *..Void for 4th scan 01293 **/ 01294 void inputScan4() 01295 { 01296 lcd.clear(); 01297 lcd.printString("Fourth Scan",0,0); 01298 lcd.refresh(); 01299 NoContinueExitScan4(); 01300 lcd.printString("X",0,1);//No Longer required line,lcd.printString("X",0,2),lcd.printString("X",0,3),lcd.printString("X",0,4),lcd.printString("X",0,5); lcd.refresh(); 01301 lcd.printString("X",15,1);//No Longer required line,lcd.printString("X",15,2),lcd.printString("X",15,3),lcd.printString("X",15,4),lcd.printString("X",15,5); lcd.refresh(); 01302 lcd.printString("X",30,1);//No Longer required line,lcd.printString("X",30,2),lcd.printString("X",30,3),lcd.printString("X",30,4),lcd.printString("X",30,5); lcd.refresh(); 01303 Buzzer.play(300,120); 01304 lcd.printString("X",45,1); 01305 lcd.refresh(); 01306 Scan1[3] = sensor.distance(); 01307 wait_ms(5);/* 01308 Buzzer.play(200,120); lcd.printString("X",45,2);lcd.refresh(); Scan4[1] = sensor.distance(); 01309 wait_ms(5); 01310 Buzzer.play(200,120); lcd.printString("X",45,3);lcd.refresh(); Scan4[2] = sensor.distance(); 01311 wait_ms(5); 01312 Buzzer.play(200,120); lcd.printString("X",45,4);lcd.refresh(); Scan4[3] = sensor.distance(); 01313 wait_ms(5); 01314 Buzzer.play(200,120); lcd.printString("X",45,5);lcd.refresh(); Scan4[4] = sensor.distance(); */ 01315 lcd.printString("Scan 4 Done",0,0); 01316 lcd.refresh(); 01317 } 01318 /** 01319 *..Void for 5th scan 01320 **/ 01321 void inputScan5() 01322 { 01323 lcd.clear(); 01324 lcd.printString("Fifth Scan",0,0); 01325 lcd.refresh(); 01326 NoContinueExitScan5(); 01327 lcd.printString("X",0,1);//No Longer required line,lcd.printString("X",0,2),lcd.printString("X",0,3),lcd.printString("X",0,4),lcd.printString("X",0,5); lcd.refresh(); 01328 lcd.printString("X",15,1);//No Longer required line,lcd.printString("X",15,2),lcd.printString("X",15,3),lcd.printString("X",15,4),lcd.printString("X",15,5); lcd.refresh(); 01329 lcd.printString("X",30,1);//No Longer required line,lcd.printString("X",30,2),lcd.printString("X",30,3),lcd.printString("X",30,4),lcd.printString("X",30,5); lcd.refresh(); 01330 lcd.printString("X",45,1);//No Longer required line,lcd.printString("X",45,2),lcd.printString("X",45,3),lcd.printString("X",45,4),lcd.printString("X",45,5); lcd.refresh(); 01331 Buzzer.play(300,120); 01332 lcd.printString("X",60,1); 01333 lcd.refresh(); 01334 Scan1[4] = sensor.distance(); 01335 wait_ms(5); /* 01336 Buzzer.play(200,120); lcd.printString("X",60,2);lcd.refresh(); Scan5[1] = sensor.distance(); 01337 wait_ms(5); 01338 Buzzer.play(200,120); lcd.printString("X",60,3);lcd.refresh(); Scan5[2] = sensor.distance(); 01339 wait_ms(5); 01340 Buzzer.play(200,120); lcd.printString("X",60,4);lcd.refresh(); Scan5[3] = sensor.distance(); 01341 wait_ms(5); 01342 Buzzer.play(200,120); lcd.printString("X",60,5);lcd.refresh(); Scan5[4] = sensor.distance(); */ 01343 lcd.printString("Scan 5 Done",0,0); 01344 lcd.refresh(); 01345 } 01346 /** 01347 *..Second Menu after B object decision if the value is plus or minus 5 of the model value on the scan a value of 1 is atributated, a match is a 0 total. 01348 **/ 01349 void inputScan6() 01350 { 01351 lcd.clear(); 01352 lcd.printString("Decide",0,0); 01353 lcd.refresh(); 01354 NoContinueExitScan6(); 01355 int box[5]= {111,38,38,111,111};// compared to the wall if the box is present this sequence should be recorded 01356 int carton[5] = {19,19,19,19,19}; // compared to the wall if the carton is present this sequence should be recorded 01357 int wall [5] = {111,111,111,111,111}; // compared to the wall if the wall is present this sequence should be recorded 01358 int triangle[5]= {111,38,19,38,111}; // compared to the wall if the triangle is present this sequence should be recorded 01359 int isBox[5]; 01360 int isCarton[5]; 01361 int isWall[5]; 01362 int isTriangle[5]; 01363 //int wallTotal; 01364 //int cartonTotal; 01365 //int boxTotal; 01366 for (int i=0; i<5; i++) { 01367 isBox[i] =abs(Scan1[i]-box[i]); 01368 printf("DeBUGGING isBOX : %i\n", isBox[i]); 01369 if (isBox[i]<=5) { 01370 isBox[i]=0; 01371 } else if (isBox[i]>5) { 01372 isBox[i]=1; 01373 } 01374 printf("DeBUGGING isBOX : %i\n", isBox[i]); 01375 boxTotal = accumulate(begin(isBox), end(isBox), 0, plus<int>()); 01376 //printf("DEBUGGING BOX total %i\n", boxTotal); 01377 01378 isCarton[i] =abs(Scan1[i]-carton[i]); 01379 printf("DeBUGGING isCarton : %i\n", isCarton[i]); 01380 if (isCarton[i]<=5) { 01381 isCarton[i]=0; 01382 } else if (isCarton[i]>5) { 01383 isCarton[i]=1; 01384 } 01385 printf("DeBUGGING isCarton : %i\n", isCarton[i]); 01386 cartonTotal = accumulate(begin(isCarton), end(isCarton), 0, plus<int>()); 01387 //printf("DEBUGGING CARTON total %i\n", cartonTotal); 01388 01389 isWall[i] =abs(Scan1[i]-wall[i]); // calculation comparing the scan value with the model 01390 printf("DeBUGGING isWall : %i\n", isWall[i]); 01391 if (isWall[i]<=5) { // if the difference is less than 5 denote 0 01392 isWall[i]=0; 01393 } else if (isWall[i]>5) { //if the distance is greater than 5 denote 1 01394 isWall[i]=1; 01395 } 01396 printf("DeBUGGING isWall : %i\n", isWall[i]); 01397 wallTotal = accumulate(begin(isWall), end(isWall), 0, plus<int>()); // sum of array 01398 //printf("DEBUGGING Wall total %i\n", wallTotal); 01399 01400 isTriangle[i] =abs(Scan1[i]-triangle[i]); 01401 printf("DeBUGGING isTriangle : %i\n", isTriangle[i]); 01402 if (isTriangle[i]<=5) { 01403 isTriangle[i]=0; 01404 } else if (isTriangle[i]>5) { 01405 isTriangle[i]=1; 01406 } 01407 printf("DeBUGGING isTriangle : %i\n", isTriangle[i]); 01408 triangleTotal = accumulate(begin(isTriangle), end(isTriangle), 0, plus<int>()); 01409 01410 printShape(); 01411 } 01412 01413 } 01414 /** 01415 *..Void for Deciding and printing shape 01416 **/ 01417 void printShape() 01418 { 01419 01420 if(wallTotal == 0) { 01421 wallDecision(); 01422 return; 01423 } else if(boxTotal == 0) { 01424 boxDecision(); 01425 return; 01426 } else if (cartonTotal == 0) { 01427 cartonDecision(); 01428 return; 01429 } else if (triangleTotal == 0) { 01430 triangleDecision(); 01431 return; 01432 } 01433 } 01434 01435 01436 01437 /** 01438 *.. Void for What to do while the Wall is in sight 01439 */ 01440 void wallDecision() 01441 { 01442 printf("We Have a wall\n"); 01443 lcd.clear(); 01444 lcd.printString("Decide",0,0); 01445 lcd.printString("Wall",0,2); 01446 lcd.refresh(); 01447 } 01448 /** 01449 *.. Void for What to do while the Box is in sight 01450 */ 01451 void boxDecision() 01452 { 01453 printf("We Have Box\n"); 01454 lcd.printString("Decide",0,0); 01455 lcd.printString("Box",0,2); 01456 lcd.refresh(); 01457 } 01458 /** 01459 *.. Void for What to do while the Carton is in sight 01460 */ 01461 void cartonDecision() 01462 { 01463 printf("We Have Carton\n"); 01464 lcd.printString("Decide",0,0); 01465 lcd.printString("Carton",0,2); 01466 lcd.refresh(); 01467 } 01468 01469 void triangleDecision() 01470 { 01471 printf("We Have Triangle\n"); 01472 lcd.printString("Decide",0,0); 01473 lcd.printString("Triangle",0,2); 01474 lcd.refresh(); 01475 }
Generated on Tue Aug 23 2022 22:47:18 by
1.7.2