Datasheet

Chapter 4 • BOE Shield-Bot Navigation
126Robotics with the BOE Shield-Bot
Positive values for the number of ms to execute the maneuver
1 to disable the servo signal
Here is what calls to this function will look like for the familiar forward-backward-left-right-
stop sequence:
maneuver(200, 200, 2000); // Forward 2 seconds
maneuver(-200, 200, 600); // Left 0.6 seconds
maneuver(200, -200, 600); // Right 0.6 seconds
maneuver(-200, -200, 2000); // Backward 2 seconds
maneuver(0, 0, -1); // Disable servos
Example Sketch - TestManeuverFunction
Create, save, and run TestManeuverFunction.
Verify that it completes the forward, left, right, backward, stop sequence.
// Robotics with the BOE Shield - TestManeuverFunction
// Move forward, left, right, then backward with maneuver function.
#include <Servo.h> // Include servo library
Servo servoLeft; // Declare left and right servos
Servo servoRight;
void setup() // Built-in initialization block
{
tone(4, 3000, 1000); // Play tone for 1 second
delay(1000); // Delay to finish tone
servoLeft.attach(13); // Attach left signal to pin 13
servoRight.attach(12); // Attach right signal to pin 12
maneuver(200, 200, 2000); // Forward 2 seconds
maneuver(-200, 200, 600); // Left 0.6 seconds
maneuver(200, -200, 600); // Right 0.6 seconds
maneuver(-200, -200, 2000); // Backward 2 seconds
maneuver(0, 0, -1); // Disable servos
}
void loop() // Main loop auto-repeats
{ // Empty, nothing needs repeating
}
void maneuver(int speedLeft, int speedRight, int msTime)
{
// speedLeft, speedRight ranges: Backward Linear Stop Linear Forward
// -200 -100...0....100 200
servoLeft.writeMicroseconds(1500 + speedLeft); // Left servo speed
servoRight.writeMicroseconds(1500 - speedRight); // Right servo speed
if(msTime==-1) // if msTime = -1