Datasheet

Shield, Lights, Servo Motors • Chapter 2
Robotics with the BOE Shield-Bot 73
Question Solutions
1. Plug the two leads into the same 5-socket row on the breadboard.
2. The
pinMode function.
3. The
digitalWrite function does both, depending on its value parameter:
digitalWrite(13, HIGH) // 5 V
digitalWrite(13, LOW) // 0 V
4. Assuming a pin has just been set high, the delay call can keep it high for a certain
amount of time. Then, a
digitalWrite call can set it low.
5. (a)1.3 ms pulses for full speed clockwise, (b)1.7 ms pulses for full speed clockwise,
and (c)1.5 ms pulses for stay still.
6. (b)
servoLeft.writeMicroseconds(1420). Full speed clockwise
is
servoLeft.writeMicroseconds(1300), and stop
is
servoLeft.WriteMicroseconds(1500). Since 1420 is further from stop and
closer to full speed, it’s the correct value for faster clockwise rotation even though it
is smaller.
7.
Servo.writeMicroseconds(value) followed by delay(ms) followed
by
Servo.writeMicroseconds(newValue) or Servo.detach(pin) will keep the
servo turning for
ms milliseconds.
Exercise Solutions
1. The total on + off time has to be 200 ms, which is 1/5th of a second. So, on for 50
ms, off for 150 ms:
void loop() // Main loop auto-repeats
{ // 200 ms -> 5 blinks/second
digitalWrite(13, HIGH); // Pin 13 = 5 V, LED emits light
delay(50); // ..for 0.05 seconds
digitalWrite(13, LOW); // Pin 13 = 0 V, LED no light
delay(150); // ..for 0.15 seconds
}
2. Set pin the 13 servo to full speed clockwise and the pin 12 servo to stop. Then,
delay for 1200. Since
servoRight is already stopped, all the code has to do is
stop
servoLeft.
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(1300); // 1.3 ms -> clockwise