Bang Bang Control
Bang Bang Control
int pa0 = 0;
int pa4 = 0;
int diff = 512; // The difference between white and black. Equal to about 512.
void setup()
{
}
void loop()
{
pa0 = analog(0);
pa4 = analog(4);
if( pa4 < diff ) // if the right sensor touch of black line.
{
sr(80); // spin right. Power 80%
}
else if( pa0 < diff ) // if the left sensor touch of black line.
{
sl(80); // spin left. Power 80%
}
else // if other. Straddling the line.
{
fd(100); // move forward. Power 100%
}
sleep(50); // wait 50 millisec.
}