Datasheet
Shield, Lights, Servo Motors • Chapter 2
Robotics with the BOE Shield-Bot • 59
void loop() // Main loop auto-repeats
{ // Empty, nothing needs repeating
}
Your Turn – Check a Second Control Signal with the Pin 12 LED
You’ll be using this code a lot, so it’s a good idea to practice declaring an instance of Servo,
attaching the signal to a pin, and setting the pulse duration.
Save LeftServoStayStill as BothServosStayStill.
Add a second Servo declaration and name it
servoRight.
Servo servoRight; // Declare right servo
Attach your servoRight signal to digital pin 12.
servoRight.attach(12); // Attach right signal to pin 12
Set the servoRight signal for 1.5 ms (1500 μs) pulses.
servoRight.writeMicroseconds(1500); // 1.5 ms stay still signal
Your sketch should now look like BothServosStayStill.
Save the sketch and run it on your Arduino.
Verify that both LEDs are at a similar brightness level.
/*
Robotics with the BOE Shield – BothServosStayStill
Generate signals to make the servos stay still for centering.
*/
#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
servoRight.attach(12); // Attach left signal to pin 12
servoLeft.writeMicroseconds(1500); // 1.5 ms stay still sig, pin 13
servoRight.writeMicroseconds(1500); // 1.5 ms stay still sig, pin 12
}
void loop() // Main loop auto-repeats
{ // Empty, nothing needs repeating