Datasheet
Chapter 2 • Shield, Lights, Servo Motors
74 • Robotics with the BOE Shield-Bot
servoRight.writeMicroseconds(1500); // 1.5 ms -> stop
delay(1200); // ..for 1.2 seconds
servoLeft.writeMicroseconds(1500); // 1.5 ms -> stop
}
3. In this example, the pin 13 servo starts counterclockwise and the pin 12 servo
starts out clockwise. This goes on for 1.5 seconds. Then, the pin 12 servo is
changed to counterclockwise, and this goes on for another 1.5 seconds. After
that, both servos are stopped.
void setup() // Built in initialization block
{
servoLeft.attach(13); // Attach left signal to pin 13
servoRight.attach(12); // Attach right signal to pin 12
servoLeft.writeMicroseconds(1700); // 1.7 ms -> cc-wise
servoRight.writeMicroseconds(1300); // 1.3 ms -> clockwise
delay(1500); // ..for 1.5 seconds
servoRight.writeMicroseconds(1700); // 1.7 ms -> cc-wise
delay(1500);
servoLeft.writeMicroseconds(1500); // 1.5 ms -> stop
servoRight.writeMicroseconds(1500); // 1.5 ms -> stop
}
Project Solutions
1. The detach function detaches the instance of Servo from its pin. This sketch
verifies that it stops the servo after 3 seconds of run time. The chapter examples
sent pulses telling the servo to stay still. In contrast,
detach stops sending
signals to the servo—the pin doesn’t tell the servo to do anything, so it goes
dormant instead of holding the “stop speed.” The end result is the same, the
servo motor stops. The advantage to
detach is that it prevents the servos from
turning slowly if the servo is not precisely calibrated.
/*
Robotics with the BOE Shield – Chapter 2, Project 1
Generate a servo full speed counterclockwise signal with pin 13 and
full speed clockwise signal with pin 12.
*/
#include <Servo.h> // Include servo library
Servo servoLeft; // Declare left servo signal
Servo servoRight; // Declare right servo signal
void setup() // Built in initialization block
{
servoLeft.attach(13); // Attach left signal to pin 13