Datasheet
Chapter 4 • BOE Shield-Bot Navigation
114 • Robotics with the BOE Shield-Bot
Press the Reset button on your board to re-run the sketch.
Measure how far your BOE Shield-Bot traveled by recording the measurement
where the wheel is now touching the ground here:_______________ (in or cm).
// Robotics with the BOE Shield - ForwardOneSecond
// Make the BOE Shield-Bot roll forward for one second, then stop.
#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
// Full speed forward
servoLeft.writeMicroseconds(1700); // Left wheel counterclockwise
servoRight.writeMicroseconds(1300); // Right wheel clockwise
delay(1000); // ...for 1 second
servoLeft.detach(); // Stop sending servo signals
servoRight.detach();
}
void loop() // Main loop auto-repeats
{ // Empty, nothing needs repeating
}
The distance you just recorded is your BOE Shield-Bot’s speed, in units per second. Now, you
can figure out how many seconds your BOE Shield-Bot has to travel to go a particular
distance.
Inches and centimeters per second: The abbreviation for inches is in, and the abbreviation for
centimeters is cm. Likewise, inches per second is abbreviated in/s, and centimeters per second is
abbreviated cm/s. Both are convenient speed measurements for the BOE Shield-Bot. There are
2.54 cm in 1 in. You can convert inches to centimeters by multiplying the number of inches by
2.54. You can convert centimeters to inches by dividing the number of centimeters by 2.54
Keep in mind that your calculations will be in terms of seconds, but the delay function will
need a parameter that’s in terms of milliseconds. So, take your result, which is in terms of
seconds, and multiply it by 1000. Then, use that value in your
delay function call. For
example, to make your BOE Shield-Bot run for 2.22 seconds, you’d use
delay(2220) after
your
writeMicroseconds calls.