Skip to content

Commit f9a2eb5

Browse files
author
Philip van Allen
committed
Cleaned up README.md, and minor fixes to ServoSequence example comments
1 parent 56bfb82 commit f9a2eb5

File tree

3 files changed

+51
-29
lines changed

3 files changed

+51
-29
lines changed

README.md

+26-21
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,34 @@
1-
VarSpeedServo
1+
VarSpeedServo.h
22
===============
33

4-
This Arduino library allows the use of up to 8 servos used with an Arduino. Since it uses interrupts, servos can run asynchronously. The libarary also permits the setting of the speed of a move, and a write() call to position can wait and only return when the move is finished.
4+
The VarSpeedServo.h Arduino library allows the use of up to 8 servos moving asynchronously (because it uses interrupts). In addition, you can set the speed of a move, optionally wait (block) until the servo move is complete, and create sequences of moves that run asynchronously.
55

6-
This code is an adaptation of the standard Arduino Servo library, which was first adapted by Korman and posted on the [Arduino forum](http://forum.arduino.cc/index.php?topic=61586.0) to add the speed capability. Philip van Allen updated it for Arduino 1.0 + and added the ability to to wait for the move to complete.
6+
This code is an adaptation of the standard Arduino Servo.h library, which was first adapted by Korman and posted on the [Arduino forum](http://forum.arduino.cc/index.php?topic=61586.0) to add the speed capability. Philip van Allen updated it for Arduino 1.0 + and added the ability to to wait for the move to complete.
77

88
* Supports up to 8 servos
99
* Allows simultaneous, asynchronous movement of all servos
10-
* Speed of the move can be set
11-
* A servo write() function to set a new position can wait for completion before returning
12-
* Allows the use of asynchronous sequences of positions, where the servo can go at a specified speed to each position in order
10+
* The speed of a move can be set
11+
* The write() function initiates a move and can optionally wait for completion of the move before returning
12+
* A servo can be sent a sequence of moves (where each move has a position and speed)
1313

1414
Sample Code
1515
----------------------------
1616

17-
#include <VarSpeedServo.h>
18-
19-
VarSpeedServo myservo; // create servo object to control a servo
20-
21-
void setup() {
22-
myservo.attach(9); // attaches the servo on pin 9 to the servo object
23-
}
24-
25-
void loop() {
26-
myservo.write(180, 30, true); // move to 180 degrees, use a speed of 30, wait until move is complete
27-
myservo.write(0, 30, true); // move to 0 degrees, use a speed of 30, wait until move is complete
28-
}
17+
```
18+
19+
#include <VarSpeedServo.h>
20+
21+
VarSpeedServo myservo; // create servo object to control a servo
22+
23+
void setup() {
24+
myservo.attach(9); // attaches the servo on pin 9 to the servo object
25+
}
26+
27+
void loop() {
28+
myservo.write(180, 30, true); // move to 180 degrees, use a speed of 30, wait until move is complete
29+
myservo.write(0, 30, true); // move to 0 degrees, use a speed of 30, wait until move is complete
30+
}
31+
```
2932

3033
Additional examples are included in the distribution and are available in the Arduino Examples section.
3134

@@ -40,17 +43,19 @@ VarSpeedServo - Class for manipulating servo motors connected to Arduino pins. M
4043
attach(pin, min, max ) - Attaches to a pin setting min and max values in microseconds
4144
default min is 544, max is 2400
4245

43-
write(value) - Sets the servo angle of value in degrees. (invalid angle that is valid as pulse in microseconds is treated as microseconds)
46+
write(value) - Sets the servo angle in degrees. (invalid angle that is valid as pulse in microseconds is treated as microseconds)
4447
write(value, speed) - speed varies the speed of the move to new position 0=full speed, 1-255 slower to faster
4548
write(value, speed, wait) - wait is a boolean that, if true, causes the function call to block until move is complete
4649

4750
writeMicroseconds() - Sets the servo pulse width in microseconds
4851
read() - Gets the last written servo pulse width as an angle between 0 and 180.
49-
readMicroseconds() - Gets the last written servo pulse width in microseconds. (was read_us() in first release)
52+
readMicroseconds() - Gets the last written servo pulse width in microseconds. (was read_us() in first release)
5053
attached() - Returns true if there is a servo attached.
5154
detach() - Stops an attached servos from pulsing its i/o pin.
5255

53-
slowmove(value, speed) - The same as write(value, speed), retained for compatibility with Korman's version
56+
slowmove(value, speed) - The same as write(value, speed), retained for compatibility with Korman's version
57+
58+
stop() - stops the servo at the current position
5459

5560
sequencePlay(sequence, sequencePositions); // play a looping sequence starting at position 0
5661
sequencePlay(sequence, sequencePositions, loop, startPosition); // play sequence with number of positions, loop if true, start at position

VarSpeedServo.cpp

+23-6
Original file line numberDiff line numberDiff line change
@@ -396,16 +396,16 @@ void VarSpeedServo::write(int value, uint8_t speed) {
396396

397397
if (speed) {
398398
if (value < MIN_PULSE_WIDTH) {
399-
// treat values less than 544 as angles in degrees (valid values in microseconds are handled as microseconds)
400-
// updated to use constrain instead of if, pva
401-
value = constrain(value, 0, 180);
402-
value = map(value, 0, 180, SERVO_MIN(), SERVO_MAX());
399+
// treat values less than 544 as angles in degrees (valid values in microseconds are handled as microseconds)
400+
// updated to use constrain instead of if, pva
401+
value = constrain(value, 0, 180);
402+
value = map(value, 0, 180, SERVO_MIN(), SERVO_MAX());
403403
}
404404
// calculate and store the values for the given channel
405405
byte channel = this->servoIndex;
406406
if( (channel >= 0) && (channel < MAX_SERVOS) ) { // ensure channel is valid
407-
// updated to use constrain instead of if, pva
408-
value = constrain(value, SERVO_MIN(), SERVO_MAX());
407+
// updated to use constrain instead of if, pva
408+
value = constrain(value, SERVO_MIN(), SERVO_MAX());
409409

410410
value = value - TRIM_DURATION;
411411
value = usToTicks(value); // convert to ticks after compensating for interrupt overhead - 12 Aug 2009
@@ -512,3 +512,20 @@ void VarSpeedServo::sequenceStop() {
512512
this->curSeqPosition = CURRENT_SEQUENCE_STOP;
513513
}
514514

515+
/*
516+
To do
517+
int VarSpeedServo::targetPosition() {
518+
byte channel = this->servoIndex;
519+
return map( servos[channel].target+1, SERVO_MIN(), SERVO_MAX(), 0, 180);
520+
}
521+
522+
int VarSpeedServo::targetPositionMicroseconds() {
523+
byte channel = this->servoIndex;
524+
return servos[channel].target;
525+
}
526+
527+
bool VarSpeedServo::isMoving() {
528+
byte channel = this->servoIndex;
529+
int servos[channel].target;
530+
}
531+
*/

examples/ServoSequence/ServoSequence.ino

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ void loop() {
2828
// read the input on analog pin 0:
2929
int sensorValue = analogRead(analogPin);
3030
if (sensorValue > 200) {
31-
myservo1.sequencePlay(slow, 3); // play sequence slowHalf that has 3 positions, loop and start at first position
31+
myservo1.sequencePlay(slow, 3); // play sequence "slowHalf" that has 3 positions, loop and start at first position
3232
} else {
33-
myservo1.sequencePlay(twitchy, 4, true, 2); // play sequence 1, loop, start at third position
33+
myservo1.sequencePlay(twitchy, 4, true, 2); // play sequence "twitchy", loop, start at third position
3434
}
3535
delay(2); // delay in between reads for analogin stability
3636
}

0 commit comments

Comments
 (0)