Datasheet
Chapter 2 • Shield, Lights, Servo Motors
56 • Robotics with the BOE Shield-Bot
Example Sketch: ServoSlowMoCcw
Create and save ServoSlowMoCcw, then run it on the Arduino.
Verify that the pin 13 LED circuit pulses briefly every two seconds.
/*
Robotics with the BOE Shield - ServoSlowMoCcw
Send 1/100th speed servo signals for viewing with an LED.
*/
void setup() // Built in initialization block
{
pinMode(13, OUTPUT); // Set digital pin 13 -> output
}
void loop() // Main loop auto-repeats
{
digitalWrite(13, HIGH); // Pin 13 = 5 V, LED emits light
delay(170); // ..for 0.17 seconds
digitalWrite(13, LOW); // Pin 13 = 0 V, LED no light
delay(1830); // ..for 1.83 seconds
}
Your Turn – Two Steps to Servo Signal
Alright, how about 1/10
th
speed instead of 1/100
th
speed?
Reduce
delay(170) to delay(17), and delay(1830) to delay(183), and re-
load the sketch.
Is the LED blinking 10 times faster now? Divide by 10 again for a full speed servo
signal—we’ll have to round the numbers a bit:
Change
delay(17) to delay(2), and delay(183) to delay(18), then run the
modified sketch.
Now you can see what the servo signal looks like with the indicator LED. The LED is
flickering so fast, it’s just a glow. Since the high signal is 2 ms instead of 1.7 ms, it’ll be a little
brighter than the actual servo control signal—the light is spending more time on. We could
use this signal and programming technique to control a servo, but there’s an easier, more
precise way. Let’s try it with LEDs first.