
Before using servo motors, you must import the Servo library. You can do this either by importing the library. You can do this either by importing the library through the Arduino IDE menu (Sketch Import Library servo) or by manually typing:
#include (servo.h)
In your software, you must first creat a new servo object before issuing instructions. You must create one object per servo motor (or group of servo motors) to contorl.
Servo frontWheels;
Servo rearWheels;
To tell the Arduino which pins the servo motors are connected to, call attach(), specifying the pin, and optionally, specifying the minimum and maximum pulse size.
servo attach (pin)
servo attach (pin, min, max)
By default, Arduino uses 544 microseconds as the minimum pulse length (equivalent to 0 degrees) and 2,400 microseconds as the maximum pulse width (equivalent to 180 degrees.) If your servo motor has different settings for a maximum and minimum pulse, you can change the values in attch () by specifying the duration in microseconds. For example, a servo motor that uses a 1 millisecond minimum and 2 millisecond maximum can be configured like this:
servo.attach (pin, 1000, 2000);
From then on, the Arduino automatically calculates the length of the pulse according to the wanted angle but will not issue commands until a function specifically orders the servo motor to move.
没有评论:
发表评论