Skip to content

Commit 1294d76

Browse files
committed
Add reference for the Hardware I/O library's SoftwareServo class
1 parent 410ccb5 commit 1294d76

File tree

6 files changed

+314
-0
lines changed

6 files changed

+314
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<root>
3+
4+
<name>SoftwareServo</name>
5+
6+
<category>I/O</category>
7+
8+
<subcategory></subcategory>
9+
10+
<usage>Application</usage>
11+
12+
<example>
13+
<image></image>
14+
<code><![CDATA[
15+
import processing.io.*;
16+
SoftwareServo servo;
17+
18+
void setup() {
19+
servo = new SoftwareServo(this);
20+
servo.attach(4);
21+
22+
// On the Raspberry Pi, GPIO 4 is pin 7 on the pin header,
23+
// located on the fourth row, above one of the ground pins
24+
}
25+
26+
void draw() {
27+
// we don't go right to the edge to prevent
28+
// making the servo unhappy
29+
float angle = 90 + sin(frameCount / 100.0)*85;
30+
servo.write(angle);
31+
}
32+
33+
]]></code>
34+
</example>
35+
36+
<description><![CDATA[
37+
Opens an RC servo motor connected to a GPIO pin<br/>
38+
</br>
39+
This library uses timers to control RC servo motors by means of pulse width
40+
modulation (PWM). While not as accurate as dedicated PWM hardware, it has
41+
shown to be sufficient for many applications.<br/>
42+
<br/>
43+
Connect the signal wire (typically colored yellow) to any available GPIO pin
44+
and control the servo's angle as shown in the example sketch.
45+
]]></description>
46+
47+
</root>
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<root>
3+
4+
<name>attach()</name>
5+
6+
<category>I/O</category>
7+
8+
<subcategory></subcategory>
9+
10+
<usage>Web &amp; Application</usage>
11+
12+
<example>
13+
<image></image>
14+
<code><![CDATA[
15+
import processing.io.*;
16+
SoftwareServo servo;
17+
18+
void setup() {
19+
servo = new SoftwareServo(this);
20+
servo.attach(4);
21+
22+
// On the Raspberry Pi, GPIO 4 is pin 7 on the pin header,
23+
// located on the fourth row, above one of the ground pins
24+
}
25+
26+
void draw() {
27+
// we don't go right to the edge to prevent
28+
// making the servo unhappy
29+
float angle = 90 + sin(frameCount / 100.0)*85;
30+
servo.write(angle);
31+
}
32+
33+
]]></code>
34+
</example>
35+
36+
<description><![CDATA[
37+
Attaches a servo motor to a GPIO pin<br/>
38+
<br/>
39+
You must call this function before calling write(). Note that the
40+
servo motor will only be instructed to move after the first time
41+
write() is called.<br/>
42+
<br/>
43+
The optional parameters minPulse and maxPulse control the minimum
44+
and maximum pulse width durations. The default values, identical to
45+
those of Arduino's Servo class, should be compatible with most servo
46+
motors.
47+
]]></description>
48+
49+
<syntax>
50+
<c>softwareservo</c>.attach()
51+
</syntax>
52+
53+
<parameter></parameter>
54+
55+
<returns></returns>
56+
57+
<related></related>
58+
59+
<availability>1.0</availability>
60+
61+
<type>Method</type>
62+
63+
<partof>Library</partof>
64+
65+
</root>
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<root>
3+
4+
<name>attached()</name>
5+
6+
<category>I/O</category>
7+
8+
<subcategory></subcategory>
9+
10+
<usage>Web &amp; Application</usage>
11+
12+
<example>
13+
<image></image>
14+
<code><![CDATA[
15+
import processing.io.*;
16+
SoftwareServo servo;
17+
18+
void setup() {
19+
servo = new SoftwareServo(this);
20+
servo.attach(4);
21+
22+
// On the Raspberry Pi, GPIO 4 is pin 7 on the pin header,
23+
// located on the fourth row, above one of the ground pins
24+
}
25+
26+
void draw() {
27+
// we don't go right to the edge to prevent
28+
// making the servo unhappy
29+
float angle = 90 + sin(frameCount / 100.0)*85;
30+
servo.write(angle);
31+
}
32+
33+
void keyPressed() {
34+
// press a key to release or re-attach the motor
35+
if (servo.attached()) {
36+
servo.detach();
37+
} else {
38+
servo.attach(4);
39+
}
40+
}
41+
42+
]]></code>
43+
</example>
44+
45+
<description><![CDATA[
46+
Returns whether a servo motor is attached to a pin
47+
]]></description>
48+
49+
<syntax>
50+
<c>softwareservo</c>.attached()
51+
</syntax>
52+
53+
<parameter></parameter>
54+
55+
<returns></returns>
56+
57+
<related></related>
58+
59+
<availability>1.0</availability>
60+
61+
<type>Method</type>
62+
63+
<partof>Library</partof>
64+
65+
</root>
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<root>
3+
4+
<name>detach()</name>
5+
6+
<category>I/O</category>
7+
8+
<subcategory></subcategory>
9+
10+
<usage>Web &amp; Application</usage>
11+
12+
<example>
13+
<image></image>
14+
<code><![CDATA[
15+
import processing.io.*;
16+
SoftwareServo servo;
17+
18+
void setup() {
19+
servo = new SoftwareServo(this);
20+
servo.attach(4);
21+
22+
// On the Raspberry Pi, GPIO 4 is pin 7 on the pin header,
23+
// located on the fourth row, above one of the ground pins
24+
}
25+
26+
void draw() {
27+
// we don't go right to the edge to prevent
28+
// making the servo unhappy
29+
float angle = 90 + sin(frameCount / 100.0)*85;
30+
servo.write(angle);
31+
}
32+
33+
void keyPressed() {
34+
// press a key to release the motor
35+
servo.detach();
36+
}
37+
38+
]]></code>
39+
</example>
40+
41+
<description><![CDATA[
42+
Detatches a servo motor from a GPIO pin<br/>
43+
<br/>
44+
Calling this method will stop the servo from moving or trying to
45+
hold the current orientation.
46+
]]></description>
47+
48+
<syntax>
49+
<c>softwareservo</c>.detach()
50+
</syntax>
51+
52+
<parameter></parameter>
53+
54+
<returns></returns>
55+
56+
<related></related>
57+
58+
<availability>1.0</availability>
59+
60+
<type>Method</type>
61+
62+
<partof>Library</partof>
63+
64+
</root>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<root>
3+
4+
<name>write()</name>
5+
6+
<category>I/O</category>
7+
8+
<subcategory></subcategory>
9+
10+
<usage>Web &amp; Application</usage>
11+
12+
<example>
13+
<image></image>
14+
<code><![CDATA[
15+
import processing.io.*;
16+
SoftwareServo servo;
17+
18+
void setup() {
19+
servo = new SoftwareServo(this);
20+
servo.attach(4);
21+
22+
// On the Raspberry Pi, GPIO 4 is pin 7 on the pin header,
23+
// located on the fourth row, above one of the ground pins
24+
}
25+
26+
void draw() {
27+
// we don't go right to the edge to prevent
28+
// making the servo unhappy
29+
float angle = 90 + sin(frameCount / 100.0)*85;
30+
servo.write(angle);
31+
}
32+
33+
]]></code>
34+
</example>
35+
36+
<description><![CDATA[
37+
Moves a servo motor to a given orientation<br/>
38+
<br/>
39+
If you are using this class in combination with a continuous rotation
40+
servo, different angles will result in the servo rotating forward or
41+
backward at different speeds. For regular servo motors, this will
42+
instruct the servo to rotate to and hold a specific angle.
43+
]]></description>
44+
45+
<syntax>
46+
<c>softwareservo</c>.write()
47+
</syntax>
48+
49+
<parameter></parameter>
50+
51+
<returns></returns>
52+
53+
<related></related>
54+
55+
<availability>1.0</availability>
56+
57+
<type>Method</type>
58+
59+
<partof>Library</partof>
60+
61+
</root>

content/api_en/LIB_io/index.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,18 @@ <h5>PWM</h5>
7676
<br />
7777
</p>
7878

79+
<h5>SoftwareServo</h5>
80+
<p>
81+
The SoftwareServo class controls RC servo motors attached to General Purpose I/O pins.<br />
82+
<br />
83+
<a href="SoftwareServo.html">SoftwareServo</a><br />
84+
<a href="SoftwareServo_attach_.html">attach()</a><br />
85+
<a href="SoftwareServo_write_.html">write()</a> <br />
86+
<a href="SoftwareServo_attached_.html">attached()</a><br />
87+
<a href="SoftwareServo_detach_.html">detach()</a><br />
88+
<br />
89+
</p>
90+
7991
<h5>SPI</h5>
8092
<p>
8193
The SPI class communicates with attached devices over SPI interfaces.<br />

0 commit comments

Comments
 (0)