Datasheet

BOE Shield-Bot Navigation • Chapter 4
Robotics with the BOE Shield-Bot 117
Keep on in this manner until the…
50th trip:
speed is 100, with servoLeft.writeMicroseconds(1600)
and
servoRight.writeMicroseconds(1400). Remember, that’s pretty close to
full speed; 1700 and 1300 are overkill.
Example Sketch: StartAndStopWithRamping
Create, save, and run the sketch StartAndStopWithRamping.
Verify that the BOE Shield-Bot gradually accelerates to full speed, maintains full
speed for a while, and then gradually decelerates to a full stop.
// Robotics with the BOE Shield - StartAndStopWithRamping
// Ramp up, go forward, ramp down.
#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
for(int speed = 0; speed <= 100; speed += 2) // Ramp up to full speed.
{
servoLeft.writeMicroseconds(1500+speed); // us = 1500,1502,... 1600
servoRight.writeMicroseconds(1500-speed); // us = 1500,1498,... 1400
delay(20); // 20 ms at each speed
}
delay(1500); // Full speed for 1.5 seconds
for(int speed = 100; speed >= 0; speed -= 2) // Ramp full speed to stop
{
servoLeft.writeMicroseconds(1500+speed); // us = 1600,1598,... 1500
servoRight.writeMicroseconds(1500-speed); // us = 1400,1402,... 1500
delay(20); // 20 ms at each speed
}
servoLeft.detach(); // Stop sending servo signals
servoRight.detach();
}
void loop() // Main loop auto-repeats
{ // Empty, nothing to repeat
}