Datasheet
Tactile Navigation with Whiskers • Chapter 5
Robotics with the BOE Shield-Bot • 161
forward(20); // Forward 1/50 of a second
}
The forward, backward, turnLeft and turnRight functions were introduced in Chapter 4,
Activity 5: Simplify Navigation with Functions on page 118, and are used in the
MovementsWithSimpleFunctions sketch. These functions certainly simplified the coding.
(Hopefully, they also help demonstrate that all the navigation coding practice from Chapter 4
has its uses!)
Your Turn
You can also modify the sketch’s if...else if...else statements to make the LED
indicators broadcast which maneuver the BOE Shield-Bot is running. Just add calls
to
digitalWrite that send HIGH and LOW signals to the indicator LED circuits. Here is an
example:
if((wLeft == 0) && (wRight == 0)) // If both whiskers contact
{
digitalWrite(8, HIGH); // Left LED on
digitalWrite(2, HIGH); // Right LED on
backward(1000); // Back up 1 second
turnLeft(800); // Turn left about 120 degrees
}
else if(wLeft == 0) // If only left whisker contact
{
digitalWrite(8, HIGH); // Left LED on
digitalWrite(2, LOW); // Right LED off
backward(1000); // Back up 1 second
turnRight(400); // Turn right about 60 degrees
}
else if(wRight == 0) // If only right whisker contact
{
digitalWrite(8, LOW); // Left LED off
digitalWrite(2, HIGH); // Right LED on
backward(1000); // Back up 1 second
turnLeft(400); // Turn left about 60 degrees
}
else // Otherwise, no whisker contact
{
digitalWrite(8, LOW); // Left LED off
digitalWrite(2, LOW); // Right LED off
forward(20); // Forward 1/50 of a second
}
Modify the if...else if...else statement in RoamingWithWhiskers to make
the BOE Shield-Bot broadcast its maneuver using the LED indicators.