Skip to content

Commit 009d16d

Browse files
authored
Merge pull request #37 from alranel/master
Port documentation to repository - DO NOT MERGE
2 parents 2e973f6 + be45d3a commit 009d16d

File tree

8 files changed

+266
-0
lines changed

8 files changed

+266
-0
lines changed

docs/api.md

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
# Servo library
2+
3+
## Methods
4+
5+
### `attach()`
6+
7+
Attach the Servo variable to a pin. Note that in Arduino 0016 and earlier, the Servo library supports only servos on only two pins: 9 and 10.
8+
9+
#### Syntax
10+
11+
```
12+
servo.attach(pin)
13+
servo.attach(pin, min, max)
14+
```
15+
16+
#### Parameters
17+
18+
* _servo_: a variable of type `Servo`
19+
* _pin_: the number of the pin that the servo is attached to
20+
* _min_ (optional): the pulse width, in microseconds, corresponding to the minimum (0-degree) angle on the servo (defaults to 544)
21+
* _max_ (optional): the pulse width, in microseconds, corresponding to the maximum (180-degree) angle on the servo (defaults to 2400)
22+
23+
#### Example
24+
25+
```
26+
#include <Servo.h>
27+
28+
Servo myservo;
29+
30+
void setup()
31+
{
32+
myservo.attach(9);
33+
}
34+
35+
void loop() {}
36+
```
37+
38+
#### See also
39+
40+
* [attached()](#attached)
41+
* [detach()](#detach)
42+
43+
### `write()`
44+
45+
Writes a value to the servo, controlling the shaft accordingly. On a standard servo, this will set the angle of the shaft (in degrees), moving the shaft to that orientation. On a continuous rotation servo, this will set the speed of the servo (with 0 being full-speed in one direction, 180 being full speed in the other, and a value near 90 being no movement).
46+
47+
#### Syntax
48+
49+
```
50+
servo.write(angle)
51+
```
52+
53+
#### Parameters
54+
55+
* _servo_: a variable of type Servo
56+
* _angle_: the value to write to the servo, from 0 to 180
57+
58+
#### Example
59+
60+
````
61+
#include <Servo.h>
62+
63+
Servo myservo;
64+
65+
void setup()
66+
{
67+
myservo.attach(9);
68+
myservo.write(90); // set servo to mid-point
69+
}
70+
71+
void loop() {}
72+
````
73+
#### See also
74+
75+
* [attach()](#attach)
76+
* [read()](#read)
77+
78+
### `writeMicroseconds()`
79+
80+
Writes a value in microseconds (uS) to the servo, controlling the shaft accordingly. On a standard servo, this will set the angle of the shaft. On standard servos a parameter value of 1000 is fully counter-clockwise, 2000 is fully clockwise, and 1500 is in the middle.
81+
82+
Note that some manufactures do not follow this standard very closely so that servos often respond to values between 700 and 2300. Feel free to increase these endpoints until the servo no longer continues to increase its range. Note however that attempting to drive a servo past its endpoints (often indicated by a growling sound) is a high-current state, and should be avoided.
83+
84+
Continuous-rotation servos will respond to the writeMicrosecond function in an analogous manner to the write function.
85+
86+
#### Syntax
87+
88+
````
89+
servo.writeMicroseconds(uS)
90+
````
91+
92+
#### Parameters
93+
94+
* _servo_: a variable of type Servo
95+
* _uS_: the value of the parameter in microseconds (int)
96+
97+
#### Example
98+
99+
````
100+
#include <Servo.h>
101+
102+
Servo myservo;
103+
104+
void setup()
105+
{
106+
myservo.attach(9);
107+
myservo.writeMicroseconds(1500); // set servo to mid-point
108+
}
109+
110+
void loop() {}
111+
````
112+
113+
#### See also
114+
115+
* [attach()](#attach)
116+
* [read()](#read)
117+
118+
119+
### `read()`
120+
121+
Read the current angle of the servo (the value passed to the last call to [write()](#write)).
122+
123+
#### Syntax
124+
125+
````
126+
servo.read()
127+
````
128+
129+
#### Parameters
130+
131+
* _servo_: a variable of type `Servo`
132+
133+
#### Returns
134+
135+
The angle of the servo, from 0 to 180 degrees.
136+
137+
#### See also
138+
139+
* [write()](#write)
140+
141+
### `attached()`
142+
143+
Check whether the Servo variable is attached to a pin.
144+
145+
#### Syntax
146+
147+
```
148+
servo.attached()
149+
```
150+
151+
#### Parameters
152+
153+
* _servo_: a variable of type `Servo`
154+
155+
#### Returns
156+
157+
`true` if the servo is attached to pin; `false` otherwise.
158+
159+
#### See also
160+
161+
* [attach()](#attach)
162+
* [detach()](#detach)
163+
164+
### `detach()`
165+
166+
Detach the Servo variable from its pin. If all Servo variables are detached, then pins 9 and 10 can be used for PWM output with [analogWrite()](#analogwrite).
167+
168+
#### Syntax
169+
170+
```
171+
servo.detach()
172+
```
173+
174+
#### Parameters
175+
176+
* _servo_: a variable of type `Servo`
177+
178+
#### See also
179+
180+
* [attach()](#attach)
181+
* [attached()](#attached)

docs/readme.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Servo library
2+
3+
4+
This library allows an Arduino board to control RC (hobby) servo motors. Servos have integrated gears and a shaft that can be precisely controlled. Standard servos allow the shaft to be positioned at various angles, usually between 0 and 180 degrees. Continuous rotation servos allow the rotation of the shaft to be set to various speeds.
5+
6+
The Servo library supports up to 12 motors on most Arduino boards and 48 on the Arduino Mega. On boards other than the Mega, use of the library disables `analogWrite()` (PWM) functionality on pins 9 and 10, whether or not there is a Servo on those pins. On the Mega, up to 12 servos can be used without interfering with PWM functionality; use of 12 to 23 motors will disable PWM on pins 11 and 12.
7+
8+
To use this library:
9+
10+
```
11+
#include <Servo.h>
12+
```
13+
14+
## Circuit
15+
16+
Servo motors have three wires: power, ground, and signal. The power wire is typically red, and should be connected to the 5V pin on the Arduino board. The ground wire is typically black or brown and should be connected to a ground pin on the Arduino board. The signal pin is typically yellow, orange or white and should be connected to a digital pin on the Arduino board. Note that servos draw considerable power, so if you need to drive more than one or two, you'll probably need to power them from a separate supply (i.e. not the +5V pin on your Arduino). Be sure to connect the grounds of the Arduino and external power supply together.
17+
18+
## Examples
19+
20+
* [Knob](https://www.arduino.cc/en/Tutorial/Knob): control the shaft of a servo motor by turning a potentiometer
21+
* [Sweep](https://www.arduino.cc/en/Tutorial/Sweep): sweeps the shaft of a servo motor back and forth

examples/Knob/images/knob_BB.png

20 KB
Loading

examples/Knob/images/knob_schem.png

26.3 KB
Loading

examples/Knob/readme.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Knob
2+
3+
Control the position of a RC (hobby) [servo motor](http://en.wikipedia.org/wiki/Servo_motor#RC_servos) with your Arduino and a potentiometer.
4+
5+
This example makes use of the Arduino `Servo` library.
6+
7+
## Hardware Required
8+
9+
* an Arduino board
10+
* Servo motor
11+
* 10k ohm potentiometer
12+
* hook-up wires
13+
14+
## Circuit
15+
16+
Servo motors have three wires: power, ground, and signal. The power wire is typically red, and should be connected to the 5V pin on the Arduino or Genuino board. The ground wire is typically black or brown and should be connected to a ground pin on the board. The signal pin is typically yellow or orange and should be connected to pin 9 on the board.
17+
18+
The potentiometer should be wired so that its two outer pins are connected to power (+5V) and ground, and its middle pin is connected to analog input 0 on the board.
19+
20+
![](images/knob_BB.png)
21+
22+
(Images developed using Fritzing. For more circuit examples, see the [Fritzing project page](http://fritzing.org/projects/))
23+
24+
## Schematic
25+
26+
![](images/knob_schem.png)
27+
28+
## See also
29+
30+
* [attach()](/docs/api.md#attach)
31+
* [write()](/docs/api.md#write)
32+
* [map()](https://www.arduino.cc/en/Reference/Map)
33+
* [analogRead()](https://www.arduino.cc/en/Reference/AnalogRead)
34+
* [Servo library reference](/docs/readme.md)
35+
* [Sweep](../Sweep) - Sweep the shaft of a servo motor back and forth

examples/Sweep/images/sweep_bb.png

18 KB
Loading

examples/Sweep/images/sweep_schem.png

20 KB
Loading

examples/Sweep/readme.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Sweep
2+
3+
Sweeps the shaft of a RC [servo motor](http://en.wikipedia.org/wiki/Servo_motor#RC_servos) back and forth across 180 degrees.
4+
5+
## Hardware Required
6+
7+
* Arduino Board
8+
* Servo Motor
9+
* Hook-up wires
10+
11+
## Circuit
12+
13+
Servo motors have three wires: power, ground, and signal. The power wire is typically red, and should be connected to the 5V pin on the Arduino or Genuino board. The ground wire is typically black or brown and should be connected to a ground pin on the board. The signal pin is typically yellow, orange or white and should be connected to pin 9 on the board.
14+
15+
![](images/sweep_bb.png)
16+
17+
(Images developed using Fritzing. For more circuit examples, see the [Fritzing project page](http://fritzing.org/projects/))
18+
19+
## Schematic
20+
21+
![](images/sweep_schem.png)
22+
23+
## See also
24+
25+
* [attach()](/docs/api.md#attach)
26+
* [write()](/docs/api.md#write)
27+
* [map()](https://www.arduino.cc/en/Reference/Map)
28+
* [Servo library reference](/docs/readme.md)
29+
* [Knob](../Knob) - Sweep the shaft of a servo motor back and forth

0 commit comments

Comments
 (0)