I build a small robot and have come up with some very basic wall avoidance code that works OK.
the basic loop i came up with is: (I think the function names are pretty self explanitory but the full code is at my other post http://arduino.cc/forum/index.php/topic,109076.0.html if you want to look)
void loop()
{
directionalPing();
if(pingLeft <= 6)
{
reverse(50);
turnRight(600);
return;
}
if(pingRight <= 6)
{
reverse(50);
turnLeft(600);
return;
}
if(pingForward <= 6)
{
reverse(200);
turnLeft(600);
return;
}
if(pingForward > 6)
{
reverse(50);
forward(150);
return;
}
}
Im pretty new to programming and I am sure there is a better way to do something like this than to run exhaustive if statements. Im not looking for code handouts, but I have been looking on them tharr interwebs for solutions and i guess I just dont know what to look for. Any code specific or general learning advice would be greatly appreciated.