define BTCONN 1 define OUTBOX 5 define OUTBOXX

  • Slides: 13
Download presentation

遙控器 � � � #define BT_CONN 1 #define OUTBOX 5 #define OUTBOXX 4 sub

遙控器 � � � #define BT_CONN 1 #define OUTBOX 5 #define OUTBOXX 4 sub BTCheck(int conn) { if(!Bluetooth. Status(conn)==NO_ERR) { Text. Out(5, LCD_LINE 2, "Error"); Wait(1000); Stop(true); } }

� � � � � task main() { BTCheck(BT_CONN); int x, y; while(true) {

� � � � � 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;

� � � � 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.

� � � 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); } }

遙控車 � � � #define INBOX 5 #define INBOXX 4 sub BTCheck(int conn) {

遙控車 � � � #define INBOX 5 #define INBOXX 4 sub BTCheck(int conn) { if(!Bluetooth. Status(conn)==NO_ERR) { Text. Out(5, LCD_LINE 2, "Error"); Wait(1000); Stop(true); } }

� � � � � task main() { BTCheck(0); int x, y, i, j,

� � � � � 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(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 {

� � � � 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.

� � � � 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.

� � � 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

End