Y Ikarashi
/
kosyusya_recieve2
narasan
Fork of kosyusya_recive by
Revision 2:31eb6fbb8119, committed 2015-03-11
- Comitter:
- eil4nyqn
- Date:
- Wed Mar 11 08:37:06 2015 +0000
- Parent:
- 1:08767e2e643b
- Commit message:
- nara2
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 08767e2e643b -r 31eb6fbb8119 main.cpp --- a/main.cpp Tue Mar 10 01:30:52 2015 +0000 +++ b/main.cpp Wed Mar 11 08:37:06 2015 +0000 @@ -1,3 +1,4 @@ +//交流ロボコンロボット側プログラム #include "mbed.h" PwmOut moter[] = {p23,p24}; @@ -8,27 +9,26 @@ int main() { uint8_t data_r1,data_r2,data_l1,data_l2,sw_data5,sw_data6,start; + uint8_t select_r,select_l,select_all,check,checker; double signal_r,signal_l; - uint8_t select_r,select_l,select_all,check,checker; - while(1){ + //初期化 select_r = 0; select_l = 0; signal_r = 0; signal_l = 0; - //if(mc.readable() == 1){ - start = mc.getc(); - data_r1 = mc.getc(); - data_r2 = mc.getc(); - data_l1 = mc.getc(); - data_l2 = mc.getc(); - sw_data5 = mc.getc(); - sw_data6 = mc.getc(); - check = mc.getc(); - - // pc.printf("%u_%u_%u_%u_%u_%u_%u/n",start,data_r1,data_r2,data_l1,data_l2,sw_data5,sw_data6); - if(start == 255){ + //受信部 + start = mc.getc(); + data_r1 = mc.getc(); + data_r2 = mc.getc(); + data_l1 = mc.getc(); + data_l2 = mc.getc(); + sw_data5 = mc.getc(); + sw_data6 = mc.getc(); + check = mc.getc(); + //加工 + if(start == 255){ if(data_r1 != 0){ signal_r = data_r1/200.0000; select_r = 16; @@ -43,22 +43,38 @@ signal_l = data_l2/200.0000; select_l = 128; } + } + else { + moter[0] = 0; + moter[1] = 0; + selecter = 0; + } + //Right + if (signal_r >= 0.6) { + signal_r = 1; + }else if(signal_r >= 0.3) { + signal_r = 0.5; + }else { + signal_r = 0; + }//Left + if (signal_l >= 0.6) { + signal_l= 1; + }else if(signal_l >= 0.3) { + signal_l = 0.5; + }else { + signal_l = 0; + } + checker = data_r1^data_r2^data_l1^data_l2^sw_data5^sw_data6; select_all = sw_data5+sw_data6+select_r+select_l; - //pc.printf("%f_%f_%d_%d_%d_%d\n",signal_a1,signal_a2,n,z,m,x); - //pc.printf("%u_\n",start); pc.printf("%u_%u_%u_%u_%u_%u_%u_%u\n",start,data_r1,data_r2,data_l1,data_l2,sw_data5,sw_data6,select_all); - //pc.printf("%u_%u\n",checker,check); - //pc.printf("%f_%f_%u_%u\n",signal_a1,signal_a2,sw_data5,sw_data6); - + if(check == checker){ moter[0] = signal_r; moter[1] = signal_l; selecter = select_all; } } - }/*else if(mc.readable() == 0){//読むとゴキブリになる文 - selecter = 0; - }*/ - } + } + \ No newline at end of file