Skip to content

Commit

Permalink
Merge branch 'release/v1.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
dadul96 committed Nov 16, 2019
2 parents 701a713 + 87d1a42 commit 058f633
Show file tree
Hide file tree
Showing 6 changed files with 384 additions and 156 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
# Servo Hardware PWM Library for Arduino Mega

This library allows Arduino/Genuino Mega boards to control up to **6 servos** with the integrated **16-bit hardware PWM timer/counter**.
This library allows Arduino/Genuino Mega boards to control up to **9 servos** with the integrated **16-bit hardware PWM timer/counter**.
16-bit hardware timer/counter (timer3, timer4 and timer5) are used to control the servos.

Unlike the original Servo.h library, this library does not use timer1.
The advantage here is that when using the Wire.h library no fluctuations in the pulse width occur.
In addition, I/O registers are addressed directly and not via the digitalWrite()-function (as in Servo.h).

Possible output pins are **pin 2, 3, 7, 8, 44,** and **45**.
Possible output pins are **pin 2, 3, 5, 6, 7, 8, 44, 45** and **46**.
**Only Arduino/Genuino Mega boards are supported!**

### Installation
This library can be installed through the Arduino IDE library manager like so:
![](installation.gif)

### Note
### Notes
Starting from version 1.3.0 this Servo-Library supports 9 instead of 6 servos! (usable pins are: 2, 3, 5, 6, 7, 8, 44, 45 and 46)

---

Starting from version 1.2.0 this Servo-Library is compatible with all the [original Arduino Servo Library](https://github.com/arduino-libraries/Servo) - commands available. In addition to these "standard"-functions, following commands are added:
* ``` attach(int pin, int min, int max, int defaultPos)``` - Besides the ability to set the servo pin and the upper and lower pulse width limit, the starting pulse width of the servo can be set with the defaultPos. This allows the servo to start from a user-defined angle instead of the middle position.
* ```detachAll()``` - This feature allows detaching all servos at once.
Expand All @@ -32,4 +36,5 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
### Acknowledgments
* Inspired by - [original Arduino Servo Library](https://github.com/arduino-libraries/Servo)
* Thanks for helping me to improve my library - [per1234](https://github.com/per1234)
* Thanks for helping me to improve my library - [QuadCorei8085](https://github.com/QuadCorei8085)
* Screen-GIF recorded with - [ShareX](https://getsharex.com/)
66 changes: 39 additions & 27 deletions examples/Servo_Sweep/Servo_Sweep.ino
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* Servo Sweep
Created by Daniel Duller, 12. January, 2019.
Changed by Daniel Duller, 11. October, 2019.
Changed by Daniel Duller, 16. November, 2019.
This example code is in the public domain.
*/

Expand All @@ -12,39 +12,51 @@ Servo myServo3;
Servo myServo4;
Servo myServo5;
Servo myServo6;
Servo myServo7;
Servo myServo8;
Servo myServo9;

unsigned int valueMicros = 0; //variable that contains the microseconds
int valueDegrees = 0; //variable that contains the degrees

void setup() {
myServo1.attach(2); //attaches the servo to pin 2
myServo2.attach(3);
myServo3.attach(7);
myServo4.attach(8);
myServo5.attach(44);
myServo6.attach(45);
myServo1.attach(2); //attaches the servo to pin 2
myServo2.attach(3);
myServo3.attach(5);
myServo4.attach(6);
myServo5.attach(7);
myServo6.attach(8);
myServo7.attach(44);
myServo8.attach(45);
myServo9.attach(46);
}

void loop() {
//option 1 - using microseconds and the writeMicroseconds-function:
for (valueMicros = 500; valueMicros < 2500; valueMicros++){ //goes from 500us to 2500us (0° to 180°)
myServo1.writeMicroseconds(valueMicros); //writes the value of valueMicros to the servo
myServo2.writeMicroseconds(valueMicros);
myServo3.writeMicroseconds(valueMicros);
myServo4.writeMicroseconds(valueMicros);
myServo5.writeMicroseconds(valueMicros);
myServo6.writeMicroseconds(valueMicros);
delay(1);
}
//option 1 - using microseconds and the writeMicroseconds-function:
for (valueMicros = 500; valueMicros < 2500; valueMicros++){ //goes from 500us to 2500us (0° to 180°)
myServo1.writeMicroseconds(valueMicros); //writes the value of valueMicros to the servo
myServo2.writeMicroseconds(valueMicros);
myServo3.writeMicroseconds(valueMicros);
myServo4.writeMicroseconds(valueMicros);
myServo5.writeMicroseconds(valueMicros);
myServo6.writeMicroseconds(valueMicros);
myServo7.writeMicroseconds(valueMicros);
myServo8.writeMicroseconds(valueMicros);
myServo9.writeMicroseconds(valueMicros);
delay(1);
}

//option 2 - using degrees and the write-function:
for (valueDegrees = 180; valueDegrees > 0; valueDegrees--){ //goes from 180° to 0° (2500us to 500us)
myServo1.write(valueDegrees); //writes the value of valueDegrees to the servo
myServo2.write(valueDegrees);
myServo3.write(valueDegrees);
myServo4.write(valueDegrees);
myServo5.write(valueDegrees);
myServo6.write(valueDegrees);
delay(10);
}
//option 2 - using degrees and the write-function:
for (valueDegrees = 180; valueDegrees > 0; valueDegrees--){ //goes from 180° to 0° (2500us to 500us)
myServo1.write(valueDegrees); //writes the value of valueDegrees to the servo
myServo2.write(valueDegrees);
myServo3.write(valueDegrees);
myServo4.write(valueDegrees);
myServo5.write(valueDegrees);
myServo6.write(valueDegrees);
myServo7.write(valueDegrees);
myServo8.write(valueDegrees);
myServo9.write(valueDegrees);
delay(10);
}
}
4 changes: 2 additions & 2 deletions extras/functions_explained.adoc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
The functions of the library are:

**Servo** -- Class for manipulating servo motors connected to Arduino pins. (**max. 6** elements)
**Servo** -- Class for manipulating servo motors connected to Arduino pins. (**max. 9** elements)

**attach(pin)** -- Attaches a servo motor to an i/o pin. (only **pin 2, 3, 7, 8, 44,** and **45**)
**attach(pin)** -- Attaches a servo motor to an i/o pin. (only **pin 2, 3, 5, 6, 7, 8, 44, 45** and **46**)

**attach(pin, min, max)** -- Attaches a servo motor to an i/o pin with a custom lower and upper pulse width limit.

Expand Down
6 changes: 3 additions & 3 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name=Servo Hardware PWM
version=1.2.1
version=1.3.0
author=Daniel Duller <[email protected]>
maintainer=Daniel Duller <[email protected]>
sentence=Allows Arduino/Genuino Mega boards to control up to 6 servos with the integrated 16-bit hardware PWM timer/counter.
paragraph=<br />This library uses the 16-bit hardware timer/counter (timer3, timer4 and timer5) to control the servos.<br />Possible output pins are pin 2, 3, 7, 8, 44, and 45.<br />Unlike the original Servo.h library, this library does not use Timer1.<br />The advantage here is that when using the Wire.h library no fluctuations in the pulse width occur.<br />In addition, I / O registers are addressed directly and not via the digitalWrite()-function (as in Servo.h).<br />
sentence=Allows Arduino/Genuino Mega boards to control up to 9 servos with the integrated 16-bit hardware PWM timer/counter.
paragraph=<br />This library uses the 16-bit hardware timer/counter (timer3, timer4 and timer5) to control the servos.<br />Possible output pins are pin 2, 3, 5, 6, 7, 8, 44, 45 and 46.<br />Unlike the original Servo.h library, this library does not use Timer1.<br />The advantage here is that when using the Wire.h library no fluctuations in the pulse width occur.<br />In addition, I / O registers are addressed directly and not via the digitalWrite()-function (as in Servo.h).<br />
category=Device Control
url=https://github.com/dadul96/Arduino-Servo-Hardware-PWM-Library
architectures=avr
Loading

0 comments on commit 058f633

Please sign in to comment.