Datasheet
Shield, Lights, Servo Motors • Chapter 2
Robotics with the BOE Shield-Bot • 67
Save the modified sketch and run it on the Arduino.
Verify that the servo connected to pin 13 now rotates the other direction, which
should be counterclockwise, at about 50 to 60 RPM.
Example Sketch: RightServoClockwise
Save LeftServoClockwise as RightServoClockwise.
Replace all instances of
servoLeft with servoRight.
Replace all instances of
13 with 12.
Save and run the modified sketch and verify that the pin 12 servo is rotating
between 50 and 60 RPM clockwise.
/*
Robotics with the BOE Shield – RightServoClockwise
Generate a servo full speed clockwise signal on digital pin 12.
*/
#include <Servo.h> // Include servo library
Servo servoRight; // Declare left servo
void setup() // Built in initialization block
{
servoRight.attach(12); // Attach left signal to pin 12
servoRight.writeMicroseconds(1300); // 1.3 ms full speed clockwise
}
void loop() // Main loop auto-repeats
{ // Empty, nothing needs repeating
}
Your Turn – Right Servo Counterclockwise
In servoRight.writeMicroseconds change (1300) to (1700).
Save the sketch under a new name and run it on your Arduino.
Verify that the pin 12 servo turns full-speed counterclockwise, 50–60 RPM.
Vdd (5 V)
GND (0 V)
1.7 ms 1.7 ms
20 ms
www.parallax.com
stan dard s ervo