Datasheet

BOE Shield-Bot Navigation • Chapter 4
Robotics with the BOE Shield-Bot 137
} while(maneuvers[index++] != 's');}
void loop() // Main loop auto-repeats
{ // Empty, nothing needs repeating
}
void go(char c) // go function
{
switch(c) // Switch to code based on c
{
case 'f': // c contains 'f'
servoLeft.writeMicroseconds(1700); // Full speed forward
servoRight.writeMicroseconds(1300);
break;
case 'b': // c contains 'b'
servoLeft.writeMicroseconds(1300); // Full speed backward
servoRight.writeMicroseconds(1700);
break;
case 'l': // c contains 'l'
servoLeft.writeMicroseconds(1300); // Rotate left in place
servoRight.writeMicroseconds(1300);
break;
case 'r': // c contains 'r'
servoLeft.writeMicroseconds(1700); // Rotate right in place
servoRight.writeMicroseconds(1700);
break;
case 's': // c contains 's'
servoLeft.writeMicroseconds(1500); // Stop
servoRight.writeMicroseconds(1500);
break;
}
delay(200); // Execute for 0.2 seconds
}
Try this arraycan you guess what it will make the BOE Shield-Bot do?
char maneuvers[] = "fffffffffflllrrrrrrlllbbbbbbbbbbs";
After the char maneuvers array and the usual initialization, these lines fetch the characters
from the array and pass them to the
go function (explained later).
int index = 0;
do
{
go(maneuvers[index]);
} while(maneuvers[index++] != 's');
First, index is declared and initialized to zero, to be used in a do-while loop. Similar to a
regular
while loop, do-while repeatedly executes commands inside its code block while a
condition is true, but the
while part comes after its block so the block always executes at