Datasheet

BOE Shield-Bot Navigation • Chapter 4
Robotics with the BOE Shield-Bot 123
pitch(3500, 500);
pitch(2000, 1500);
Notice that each of these calls to pitch includes two values, one to pass to
the
Hz parameter, and one to pass to the ms parameter. The number of values in a function
call must match the number of parameters in that function’s definition, or the sketch won’t
compile.
Save FunctionCallWithParameter as FunctionCallWithTwoParameters.
Replace the
pitch function with the two-parameter version.
Replace the single parameter
pitch calls with the two-parameter calls.
Run the modified sketch and verify that it works.
Put Maneuvers Into Functions
Let’s try putting the forward, turnLeft, turnRight, and backward navigation routines
inside functions. Here’s an example:
Example Sketch MovementsWithSimpleFunctions
Create, save, and run MovementsWithSimpleFunctions.
// Robotics with the BOE Shield - MovementsWithSimpleFunctions
// Move forward, left, right, then backward for testing and tuning.
#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
forward(2000); // Go forward for 2 seconds
turnLeft(600); // Turn left for 0.6 seconds
turnRight(600); // Turn right for 0.6 seconds
backward(2000); // go backward for 2 seconds
disableServos(); // Stay still indefinitely
}
void loop() // Main loop auto-repeats
{ // Empty, nothing needs repeating