# define BTCONN 1 define OUTBOX 5 define OUTBOXX

• Slides: 13

� � � � � task main() { BTCheck(BT_CONN); int x, y; while(true) { Clear. Screen(); x=Motor. Tacho. Count(OUT_B); y=Motor. Tacho. Count(OUT_C)/4;

� � � � if(x>100) x=100; else if(x<-100) x=-100; if(y>100) y=100; else if(y<-100) y=-100;

� � � Num. Out(10, LCD_LINE 2, x); Num. Out(10, LCD_LINE 4, y); Send. Remote. Number(BT_CONN, OUTBOX, x); Send. Remote. Number(BT_CONN, OUTBOXX, y); } }

� � � � � task main() { BTCheck(0); int x, y, i, j, k, l; int smp=1; while(true) { Receive. Remote. Number(INBOX, false, x); Receive. Remote. Number(INBOXX, false, y);

� � � � if(y>0 && x>=0) //前進左轉 { if(x==0) i=-y; else { i=x-y; if(i<0) i=0; } On. Fwd. Reg(OUT_B, x, OUT_REGMODE_SPEED); On. Fwd. Reg(OUT_C, i, OUT_REGMODE_SPEED); }

� � � � else if(y<0 && x>=0) //前進右轉 { if(x==0) j=y; else { j=x+y; if(j<0) j=0; } On. Fwd. Reg(OUT_B, j, OUT_REGMODE_SPEED); On. Fwd. Reg(OUT_C, x, OUT_REGMODE_SPEED); }

� � � � else if(y>0 && x<0) //後退左轉 { k=x+y; if(k>0) k=0; On. Fwd. Reg(OUT_B, x, OUT_REGMODE_SPEED); On. Fwd. Reg(OUT_C, k, OUT_REGMODE_SPEED); }

� � � else if(y<0 && x<0) //後退右轉 { l=x-y; if(l>0) l=0; On. Fwd. Reg(OUT_B, l, OUT_REGMODE_SPEED); On. Fwd. Reg(OUT_C, x, OUT_REGMODE_SPEED); } else //直線前進後退 On. Fwd. Reg(OUT_BC, x, OUT_REGMODE_SPEED); } }

End