SOURCE CODE


We controlled a line tracer as simulation of machine control of botball. If only the central sensor reacts, in advance before. If only the right sensor reacts, in advance to the right. If only the left sensor reacts, in advance to the left. It was able to go ahead through zigzag by these data. When a limit switch of the tip reacted, its urgently stops.

#define PA 0x320
#define PB 0x321
#define PC 0x322
#define CW 0x323
void move();
void right();
void left();
int pr=0,pl=0;
main()
{
int s,a[4];
a[0]=0xcc,a[1]=0x66,a[2]=0x33,a[3]=0x99;
out(0x94,0x300,2);
out(0x96,0x408,2);
out(CW,0x90,1);
while((inp(PA) & 0xc0)==0){
s=inp(PA) & 0x07;
switch(s){
case 0x01: right(a);
break;
case 0x04: left(a);
break;
default: move(a);
break;
}
}
}
void move(b)
int b[];
{
if(pr==3)pr=0;
else pr++;
if(pl==0)pl=3;
else pl--;
out(PB,b[pr],1);
out(PC,b[pl],1);
}
void right(c)
int c[];
{
if(pr==0)pr=3;
else pr--;
if(pl==0)pl=3;
else pl--;
out(PB,c[pr],1);
out(PC,c[pl],1);
}
void left(d)
int d[];
{
if(pr==3)pr=0;
else pr++;
if(pl==3)pl=0;
else pl++;
out(PB,d[pr],1);
out(PC,d[pl],1);
}