Syntax
class Servo;
ContentsIndex
PreviousUpNext
Servo Class
Members | Example
Syntax
class Servo;
Description

Use the servo library to enable RC servo control on a LinkIt ONE circuit board. Servo integrates gears and axes to provide accurate control. 

A standard servo system positions an axis in different angles, normally between 0 and 180 degrees. A rotating servo sets the rotation of axis to different speeds continuously.

Example
#include <Servo.h>
Servo myservo;
 
int potpin = 0;
int val;
 
void setup()
{
  myservo.attach(9);                // The servo connecting to pin 9.
}
 
void loop()
{
  val = analogRead(potpin);         // Reads from Pot pin.
  val = map(val, 0, 1023, 0, 180);  // Map value from 0~1023 to 0~180.
  myservo.write(val);               // The control servo.
  delay(200);
}
Class Hierarchy
File

Servo.h

Notes

Only pin (D3, D9) with PWM functionality can be used by the servo. 

 

Group
Methods
Method 
Description 
Attaches a servo motor to a digital pin. Only digital pins supporting PWM (D3, D9) can use this function. 
Attaches servo motor to a digital pin. Only digital pins supporting PWM (D3, D9) can use this function. 
Detects if servo has been attached with a pin. 
To detach servo motor and pin. If all servo motors are bound, you can use PWM output and analogWrite for output. 
read 
Reads the current rotation angle of the servo motor. 
Writes a value to servo to control the corresponding lever. Sets up the lever angle for a standard servo motor in order to move the lever to the corresponding angle. To set up the rotation speed for a continuously rotating servo motor, use 0 to rotate in one direction in full speed; 180 to rotate in the opposite direction in full speed; and 90 to stay intact. 
Writes a value to servo to control the corresponding lever. Sets up the rotation angle of a standard servo motor. In terms of parameters for a standard servo: 1000 means rotating counterclockwise in full speed. 2000 means clockwise in full speed. 1500 means in the middle.
The following is extracted from Arduino's official website: For customers who do not operate following the standard method, for example by setting the response value of servo between 700 and 2300, in attempt to enlarge the limits to adjust the range of rotation. However, such operation may shorten the life of a servo and... more