hahaha
Dependencies: mbed
Diff: main.cpp
- Revision:
- 2:ce3ee4bc8cf7
- Parent:
- 1:d8ce226c8c2e
--- a/main.cpp Tue Dec 06 06:11:54 2016 +0000 +++ b/main.cpp Tue Dec 06 12:19:49 2016 +0000 @@ -1,7 +1,6 @@ #include "mbed.h" #include "bmu.h" - InterruptIn lim(D3); InterruptIn rotate(D4); InterruptIn choose(D5); @@ -124,38 +123,39 @@ { for (int i = 0;i<siz;i++) { - mas.putc(char(arrayi[i])); - wait(it); + mas.putc(char(arrayi[i]));UUpdate(); + wait(it);UUpdate(); } } void getStr() { + UUpdate(); while (mas.readable()) { - elem = mas.getc(); - pc.printf("char is %d\n\r",elem); + elem = mas.getc();UUpdate(); + pc.printf("char is %d\n\r",elem);UUpdate(); if ((elem == '\n')) { - pc.printf("string is %s\n\r",data); + pc.printf("string is %s\n\r",data);UUpdate(); for(int i=0;i<indx;i++) { if (indx > 2) { - dete[i] = data[i]; + dete[i] = data[i];UUpdate(); } } for(int i=0;i<30;i++) { data[i] = '\0'; } - indx = 0; + indx = 0;UUpdate(); break; }else { - data[indx] = elem; - indx += 1; + data[indx] = elem;UUpdate(); + indx += 1;UUpdate(); } } @@ -165,71 +165,71 @@ if (t.read() > 1) { - duino.putc(lis[23]); + duino.putc(lis[23]);UUpdate(); - timer.reset(); + timer.reset();UUpdate(); } } void LWin(){ //ชนะ if ( timer.read() > 1) { //pc.printf("Writing!\n\r"); - duino.putc( lis[0]); - duino.putc( lis[1]); - duino.putc( lis[2]); - timer.reset(); + duino.putc( lis[0]);UUpdate(); + duino.putc( lis[1]);UUpdate(); + duino.putc( lis[2]);UUpdate(); + timer.reset();UUpdate(); } } void LCountDown(int ixxii){ //นับเวลา if ( timer.read() > 1) { - duino.putc(ixxii); - timer.reset(); + duino.putc(ixxii);UUpdate(); + timer.reset();UUpdate(); } } void LCorrect(){ //เช็คถูก if ( timer.read() > 1) { - //pc.printf("Writing!\n\r"); - duino.putc(lis[18]); - timer.reset(); + //pc.printf("Writing!\n\r");UUpdate(); + duino.putc(lis[18]);UUpdate(); + timer.reset();UUpdate(); } } void LError(){ // if ( timer.read() > 1) { - //pc.printf("Writing!\n\r"); - duino.putc( lis[19]); - timer.reset(); + //pc.printf("Writing!\n\r");UUpdate(); + duino.putc( lis[19]);UUpdate(); + timer.reset();UUpdate(); } } void LMapComplete(){ //ลงค่าเสร็จ if ( timer.read() > 1) { - //pc.printf("Writing!\n\r"); + //pc.printf("Writing!\n\r");UUpdate(); - duino.putc( lis[20]); + duino.putc( lis[20]);UUpdate(); - timer.reset();}} + timer.reset();UUpdate();}} void LWbox(){ //ตัวหลัก if ( timer.read() > 1) { - duino.putc( lis[21]); - timer.reset(); + duino.putc( lis[21]);UUpdate(); + timer.reset();UUpdate(); } } void LRotateComplete(){ //หมุน if ( timer.read() > 1) { - //pc.printf("Writing!\n\r"); + //pc.printf("Writing!\n\r");UUpdate(); - duino.putc( lis[22]); + duino.putc( lis[22]);UUpdate(); - timer.reset(); + timer.reset();UUpdate(); } } @@ -239,11 +239,11 @@ if ( t.read() > 1) { //pc.printf("Writing!\n\r"); - duino.putc( lis[3]); - duino.putc( lis[4]); - duino.putc( lis[5]); - duino.putc( lis[6]); - t.reset(); + duino.putc( lis[3]);UUpdate(); + duino.putc( lis[4]);UUpdate(); + duino.putc( lis[5]);UUpdate(); + duino.putc( lis[6]);UUpdate(); + t.reset();UUpdate(); } if ( duino.readable()) { @@ -254,13 +254,13 @@ void Lose() { - LLose(); + LLose();UUpdate(); Sent("los\n",0.1,4); } void Win() { - LWin(); + LWin();UUpdate(); Sent("lwin\n",0.1,4); } @@ -334,20 +334,20 @@ { if (xx != -1) { - WMbox[0] = xx; - WMbox[1] = yy; - WMbox[2] = zz; - WMbox[3] = lx; - WMbox[4] = ly; - WMbox[5] = lz; + WMbox[0] = xx;UUpdate(); + WMbox[1] = yy;UUpdate(); + WMbox[2] = zz;UUpdate(); + WMbox[3] = lx;UUpdate(); + WMbox[4] = ly;UUpdate(); + WMbox[5] = lz;UUpdate(); }else { - WMbox[0] = lx; - WMbox[1] = ly; - WMbox[2] = lz; - WMbox[3] = xx; - WMbox[4] = yy; - WMbox[5] = zz; + WMbox[0] = lx;UUpdate(); + WMbox[1] = ly;UUpdate(); + WMbox[2] = lz;UUpdate(); + WMbox[3] = xx;UUpdate(); + WMbox[4] = yy;UUpdate(); + WMbox[5] = zz;UUpdate(); } } @@ -355,14 +355,14 @@ { if (box) { - WMbox[0] = -1; - WMbox[1] = -1; - WMbox[2] = -1; + WMbox[0] = -1;UUpdate(); + WMbox[1] = -1;UUpdate(); + WMbox[2] = -1;UUpdate(); }else { - WMbox[3] = -1; - WMbox[4] = -1; - WMbox[5] = -1; + WMbox[3] = -1;UUpdate(); + WMbox[4] = -1;UUpdate(); + WMbox[5] = -1;UUpdate(); } } @@ -376,10 +376,10 @@ { for(int k=0;k<5;k++) { - A = ((i-2)* Cross(pitch))+((k-2)* Zine(pitch)); - B = ((j-2)* Cross(yaw))+((i-2)* Zine(pitch)* Zine(yaw))-((k-2)* Zine(yaw)* Cross(pitch)); - C = ((j-2)* Zine(yaw))-((i-2)* Cross(yaw)* Zine(pitch))+((k-2)* Cross(yaw)* Cross(pitch)); - rmap[i+2][j+2][k+2]= map[i][j][k]; + A = ((i-2)* Cross(pitch))+((k-2)* Zine(pitch));UUpdate(); + B = ((j-2)* Cross(yaw))+((i-2)* Zine(pitch)* Zine(yaw))-((k-2)* Zine(yaw)* Cross(pitch));UUpdate(); + C = ((j-2)* Zine(yaw))-((i-2)* Cross(yaw)* Zine(pitch))+((k-2)* Cross(yaw)* Cross(pitch));UUpdate(); + rmap[i+2][j+2][k+2]= map[i][j][k];UUpdate(); } } } @@ -391,10 +391,10 @@ { for(int k=0;k<5;k++) { - A = ((i-2)* Cross(yaw)) + ((j-2)* Zine(role)* Zine(yaw)) +((k-2)* Zine(yaw)* Cross(role)); - B = ((j-2)* Cross(role))-((k-2)* Zine(role)); - C = -((i-2)* Zine(yaw))+((j-2)* Cross(yaw)* Zine(role))+((k-2)* Cross(yaw)* Cross(role)); - rmap[i+2][j+2][k+2]= map[i][j][k]; + A = ((i-2)* Cross(yaw)) + ((j-2)* Zine(role)* Zine(yaw)) +((k-2)* Zine(yaw)* Cross(role));UUpdate(); + B = ((j-2)* Cross(role))-((k-2)* Zine(role));UUpdate(); + C = -((i-2)* Zine(yaw))+((j-2)* Cross(yaw)* Zine(role))+((k-2)* Cross(yaw)* Cross(role));UUpdate(); + rmap[i+2][j+2][k+2]= map[i][j][k];UUpdate(); } } } @@ -406,10 +406,10 @@ { for(int k=0;k<5;k++) { - A = ((i-2)* Cross(yaw))-((j-2)* Zine(yaw)); - B = ((i-2)* Zine(yaw))+((j-2)* Cross(yaw)); - C = (k-2); - rmap[i+2][j+2][k+2]= map[i][j][k]; + A = ((i-2)* Cross(yaw))-((j-2)* Zine(yaw));UUpdate(); + B = ((i-2)* Zine(yaw))+((j-2)* Cross(yaw));UUpdate(); + C = (k-2);UUpdate(); + rmap[i+2][j+2][k+2]= map[i][j][k];UUpdate(); } } } @@ -420,7 +420,7 @@ { for(int k=0;k<5;k++) { - map[i][j][k]= rmap[i][j][k]; + map[i][j][k]= rmap[i][j][k];UUpdate(); } } } @@ -434,34 +434,34 @@ case '0': i-- , j-- , k--; if( map[i][j][k] == 0){ - map[i][j][k] = 5; // 5 = 'x' - turn++; + map[i][j][k] = 5;UUpdate(); // 5 = 'x' + turn++;UUpdate(); } else{ - Lose(); // ลงไมไ่ด้ + Lose();UUpdate(); // ลงไมไ่ด้ } case '1': i-- , j-- , k--; if( map[i][j][k] == 0){ - map[i][j][k] = 6; // 6 = 'o' - turn++; + map[i][j][k] = 6;UUpdate(); // 6 = 'o' + turn++;UUpdate(); } else{ - Lose(); // ลงไมไ่ด้ + Lose();UUpdate(); // ลงไมไ่ด้ } } if(i == 5 or j == 5 or k == 5){ // ลงเกิน map - Lose(); + Lose();UUpdate(); } for(i=0 ; i<5 ; i++){ //แนว k for(j=0 ; j<5 ; j++){ for(k=0 ; k<3 ; k++){ if( map[i][j][k] and map[i][j][k+1] and map[i][j][k+2] == 5){ - Win(); + Win();UUpdate(); } else if( map[i][j][k] and map[i][j][k+1] and map[i][j][k+2] == 6){ - Win(); + Win();UUpdate(); } } } @@ -471,10 +471,10 @@ for(k=0 ; k<5 ; k++){ for(j=0 ; j<3 ; j++){ if( map[i][j][k] and map[i][j+1][k] and map[i][j+2][k] == 5){ - Win(); + Win();UUpdate(); } else if( map[i][j][k] and map[i][j+1][k] and map[i][j+2][k] == 6){ - Win(); + Win();UUpdate(); } } } @@ -484,10 +484,10 @@ for(k=0 ; k<5 ; k++){ for(i=0 ; i<3 ; i++){ if( map[i][j][k] and map[i+1][j][k] and map[i+2][j][k] == 5){ - Win(); + Win();UUpdate(); } else if( map[i][j][k] and map[i+1][j][k] and map[i+2][j][k] == 6){ - Win(); + Win();UUpdate(); } } } @@ -497,10 +497,10 @@ for(j=0 ; j<3 ; j++){ for(k=0 ; k<3 ; k++){ if( map[i][j][k] and map[i][j+1][k+1] and map[i][j+2][k+2] == 5){ - Win(); + Win();UUpdate(); } else if( map[i][j][k] and map[i][j+1][k+1] and map[i][j+2][k+2] == 6){ - Win(); + Win();UUpdate(); } } } @@ -510,10 +510,10 @@ for(i=0 ; i<3 ; i++){ for(k=0 ; k<3 ; k++){ if( map[i][j][k] and map[i+1][j][k+1] and map[i+2][j][k+2] == 5){ - Win(); + Win();UUpdate(); } else if( map[i][j][k] and map[i+1][j][k+1] and map[i+2][j][k+2] == 6){ - Win(); + Win();UUpdate(); } } } @@ -523,10 +523,10 @@ for(i=0 ; i<3 ; i++){ for(j=0 ; j<3 ; j++){ if( map[i][j][k] and map[i+1][j+1][k] and map[i+2][j+2][k] == 5){ - Win(); + Win();UUpdate(); } else if( map[i][j][k] and map[i+1][j+1][k] and map[i+2][j+2][k] == 6){ - Win(); + Win();UUpdate(); } } } @@ -536,10 +536,10 @@ for(j=0 ; j<3 ; j++){ for(k=4 ; k>1 ; k--){ if( map[i][j][k] and map[i][j+1][k-1] and map[i][j+2][k-2] == 5){ - Win(); + Win();UUpdate(); } else if( map[i][j][k] and map[i][j+1][k-1] and map[i][j+2][k-2] == 6){ - Win(); + Win();UUpdate(); } } } @@ -549,10 +549,10 @@ for(i=0 ; i<3 ; i++){ for(k=4 ; k>1 ; k--){ if( map[i][j][k] and map[i+1][j][k-1] and map[i+2][j][k-2] == 5){ - Win(); + Win();UUpdate(); } else if( map[i][j][k] and map[i+1][j][k-1] and map[i+2][j][k-2] == 6){ - Win(); + Win();UUpdate(); } } } @@ -562,10 +562,10 @@ for(i=0 ; i<3 ; i++){ for(j=4 ; j>1 ; j--){ if( map[i][j][k] and map[i+1][j-1][k] and map[i+2][j-2][k] == 5){ - Win(); + Win();UUpdate(); } else if( map[i][j][k] and map[i+1][j-1][k] and map[i+2][j-2][k] == 6){ - Win(); + Win();UUpdate(); } } } @@ -574,10 +574,10 @@ for(j=0 ; j<3 ; j++){ for(k=0 ; k<3 ; k++){ if( map[i][j][k] and map[i+1][j+1][k+1] and map[i+2][j+2][k+2] == 5){ - Win(); + Win();UUpdate(); } else if( map[i][j][k] and map[i+1][j+1][k+1] and map[i+2][j+2][k+2] == 6){ - Win(); + Win();UUpdate(); } } } @@ -586,10 +586,10 @@ for(j=0 ; j<3 ; j++){ for(k=0 ; k<3 ; k++){ if( map[i][j][k] and map[i-1][j+1][k+1] and map[i-2][j+2][k+2] == 5){ - Win(); + Win();UUpdate(); } else if( map[i][j][k] and map[i-1][j+1][k+1] and map[i-2][j+2][k+2] == 6){ - Win(); + Win();UUpdate(); } } } @@ -598,10 +598,10 @@ for(j=4 ; j>1 ; j--){ for(k=0 ; k<3 ; k++){ if( map[i][j][k] and map[i-1][j-1][k+1] and map[i-2][j-2][k+2] == 5){ - Win(); + Win();UUpdate(); } else if( map[i][j][k] and map[i-1][j-1][k+1] and map[i-2][j-2][k+2] == 6){ - Win(); + Win();UUpdate(); } } } @@ -610,10 +610,10 @@ for(j=4 ; j>1 ; j--){ for(k=0 ; k<3 ; k++){ if( map[i][j][k] and map[i+1][j-1][k+1] and map[i+2][j-2][k+2] == 5){ - Win(); + Win();UUpdate(); } else if( map[i][j][k] and map[i+1][j-1][k+1] and map[i+2][j-2][k+2] == 6){ - Win(); + Win();UUpdate(); } } } @@ -631,14 +631,14 @@ for( B=0 ; B<5 ; B++){ for( C=0 ; C<5 ; C++){ if( map[ A][ B][ C] == 5){ - Check1[ A][ B][ C] = 1; + Check1[ A][ B][ C] = 1;UUpdate(); } else if( map[ A][ B][ C] == 6){ - Check2[ A][ B][ C] = 1; + Check2[ A][ B][ C] = 1;UUpdate(); } else{ - Check1[ A][ B][ C] = 0; - Check2[ A][ B][ C] = 0; + Check1[ A][ B][ C] = 0;UUpdate(); + Check2[ A][ B][ C] = 0;UUpdate(); } } } @@ -661,7 +661,7 @@ UUpdate(); }*/ //LInitial(); // set initial pattern in led matrix. - //wait(5); // wait 5 second for putting the box down to set initial position of imu. + wait(5); // wait 5 second for putting the box down to set initial position of imu. //imu.Initial(); // set initial for imu. //Update.attach(&UUpdate,0.1); //timer interrupt for recieving bluetooth. //while((dete[0]!='i')||(dete[1]!='n')||(dete[2]!='i')||(dete[3]!='t')) @@ -671,13 +671,13 @@ t.start(); while (1) // void loop. { - state = 1; + state = 1;UUpdate(); UUpdate(); if (buttonState[0] == 1) // if the boxes are connected. { - x = GetCoordinateX(); - y = GetCoordinateY(); - z = GetCoordinateZ(); // get the position of main box which linking with map or the box not be choosen. + x = GetCoordinateX();UUpdate(); + y = GetCoordinateY();UUpdate(); + z = GetCoordinateZ();UUpdate(); // get the position of main box which linking with map or the box not be choosen. /*Sent("helr\n",0.1,5); // tell the other box, that we want helper roll. while((dete[0]!='h')||(dete[1]!='e')||(dete[2]!='l')||(dete[3]!='r')) { @@ -698,62 +698,62 @@ helperYaw = int( ((int(dete[4+ii])-48)*100)+((int(dete[5+ii])-48)*10)+(int(dete[6+ii])-48) ); //get roll from another box.*/ //Sent("ok\n",0.1,3); //free the otherbox. - errorie = imu.Getposition(x,y,z);//,helperRoll,helperPitch,helperYaw); // calculate position from imu. + errorie = imu.Getposition(x,y,z);//,helperRoll,helperPitch,helperYaw);UUpdate(); // calculate position from imu. if (errorie) { - LError(); + LError();UUpdate(); while(buttonState[0] == 1) { UUpdate(); } }else { - lx = x; - ly = y; - lz = z; - x = imu.X_pos; - y = imu.Y_pos; - z = imu.Z_pos; // get new possition. + lx = x;UUpdate(); + ly = y;UUpdate(); + lz = z;UUpdate(); + x = imu.X_pos;UUpdate(); + y = imu.Y_pos;UUpdate(); + z = imu.Z_pos;UUpdate(); // get new possition. - UpdateMap(x,y,z,turn);//,helperRoll); //update new position in map. + UpdateMap(x,y,z,turn);UUpdate();//,helperRoll); //update new position in map. - ChangeOX(x,y,z,lx,ly,lz); + ChangeOX(x,y,z,lx,ly,lz);UUpdate(); Sent("mapc\n",0.1,4); //map complete. - LMapComplete(); // show that this position is ok. + LMapComplete();UUpdate(); // show that this position is ok. while(1) { UUpdate(); - anach = chooseAnother() ;// wheather thr others box is choosen. + anach = chooseAnother() ;UUpdate();// wheather thr others box is choosen. if ((buttonState[2]==1) && (!anach)) { Sent("ch1\n",0.1,4); - Choose(1); // choose main box. + Choose(1);UUpdate(); // choose main box. }else if((buttonState[2]==0) && (anach)) { - Choose(0); // choose another box. + Choose(0);UUpdate(); // choose another box. }else if(buttonState[2]==0) { if((buttonState[1]==0)||(anotherRotate())) // click buutton some rotate box. { - state = 3; + state = 3;UUpdate(); while((buttonState[1]==0)&&(anotherRotate())) { UUpdate(); } - yyaaww = imu.Rotate(); // check wheater rotating is error. - MapRotate(0,0,yyaaww);//imu.Rotate_Yaw); // private variable/arttribute in imu class. - LRotateComplete(); + yyaaww = imu.Rotate();UUpdate(); // check wheater rotating is error. + MapRotate(0,0,yyaaww);UUpdate();//imu.Rotate_Yaw); // private variable/arttribute in imu class. + LRotateComplete();UUpdate(); } } //close choose or rotate. } //close while true. - turn ++; + turn ++;UUpdate(); Sent("T++\n",0.1,4); - t.start(); - state = 2; + t.start();UUpdate(); + state = 2;UUpdate(); //LChooseComplete(); } // close not error. @@ -761,18 +761,18 @@ { if (county == 0) // time out. { - t.stop(); - Lose(); // lose state + t.stop();UUpdate(); + Lose();UUpdate(); // lose state }else if(turn != 0) { - t.stop(); - if (t.read() > 1.0); + t.stop();UUpdate(); + if (t.read() > 1.0) { - t.start(); - county -= 1; // time decreasing. + t.start();UUpdate(); + county -= 1;UUpdate(); // time decreasing. } } // close check time - LCountDown(county); + LCountDown(county);UUpdate(); Sent("Tur\n",0.1,4); } // close boxes aren't connect.