Hardware Reference
In-Depth Information
The angle parameter is an integer number, from 0 to 180, and represents the
angle in degrees.
If you require precision, you can specify the length of the pulse by using
the writeMicroseconds() function. This eliminates the need for calculation
by the Arduino and specii es the exact pulse length, an integer, expressed in
microseconds:
servo.writeMicroseconds(microseconds);
It does not matter what the original position was, the servo motor automati-
cally adjusts its position. The Arduino does not need to calculate this either;
all the intelligence is embedded inside the motor assembly. It does, however,
keep the last angle that it was instructed to use, and this value can be fetched
with read() :
int angle = servo.read()
Remember that servo motors can receive only instructions and not return
information. The value returned by read() is the value inside the Arduino.
When connecting a servo motor, there is no way to know what position it was
in initially. It can be helpful to set a servo motor to a default position before
starting your application. (For example, a remote-controlled car should prob-
ably have the wheels turn so that they are at 90 degrees; without adjusting the
steering, the owner would expect the car to go straight and not at an angle.)
Servo motors and other physical objects take time to get to where you want
them to be, so it's considered good practice to give your motor a bit of time to
get where it wants to go. Some motors move faster than others, if you're unsure
of how much time you'll need, it's best to check your motor's documentation.
Disconnecting
If required, servo motors can be disconnected inside sketches. To disconnect a
servo, use detach() :
servo.detach()
Subsequent calls to attached() return false , and no more signals will be
sent until the sketch calls attach() again.
Servo motors can be attached, detached, and re-attached in software. Sometimes
a sketch needs to know the status of the devices connected at that time. To see
if a servo motor is connected, you can use attached() :
result = servo.attached();
This function returns 1 (or true ) if a servo motor has been declared as attached,
and 0 (or false ) otherwise. Note that this won't tell you if your motor is physi-
cally attached or not, just that it is connected in software.
 
Search WWH ::




Custom Search