Skip to content

Commit bb00a98

Browse files
committed
Housekeeping, added USE_USER_PROVIDED_SERVO_LIB macro and bumped version to 3.3.0
1 parent bf7deda commit bb00a98

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+966
-87
lines changed

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ Contains the [QuadrupedControl](https://github.com/ArminJo/QuadrupedControl) exa
7474

7575
# Servo easing library for Arduino
7676
Its purpose is to interpolate the movement between two servo positions set by software.<br/>
77-
If your servo control data is e.g. generated by an joystick or other *"slow"* changing inputs and therefore does not change suddenly or does not jump, **you most likely do not need this library!**, you may consider to use a **digital low pass** or **[simple EMA filters](https://github.com/ArminJo/Arduino-Utils#simpleemafilterscpp)** to smooth your values used to control the servos.<br/>
77+
If your servo control data is e.g. generated by an joystick or other *"slow"* changing inputs and therefore does not change suddenly or does not jump, **you most likely do not need this library!**, you may consider to use a **digital low pass** or **[simple EMA filters](https://github.com/ArminJo/Arduino-Utils?tab=readme-ov-file#simpleemafilters)** to smooth your values used to control the servos.<br/>
7878
ServoEasing works with the Arduino Servo library as well as with [PCA9685 servo expanders](https://learn.adafruit.com/16-channel-pwm-servo-driver?view=all).
7979
The expander in turn requires the Arduino Wire library or a [compatible one](https://github.com/felias-fogg/SoftI2CMaster) and is bound to their restrictions.<br/>
8080
For **ESP32** you need to install the Arduino ESP32Servo library.<br/>
@@ -283,9 +283,10 @@ Modify them by enabling / disabling them, or change the values if applicable.
283283
| `PCA9685_ACTUAL_CLOCK_FREQUENCY` | 25000000L | Change it, if your PCA9685 has another than the default 25 MHz internal clock. See chapter 2 and 5 of the PCA9685 Datasheet "25 MHz typical internal oscillator requires no external components". This value is taken for all attached PCA9685 expanders! |
284284
| `USE_SOFT_I2C_MASTER` | disabled | Saves up to 1756 bytes program memory and 218 bytes RAM for PCA9685 I2C communication compared with Arduino Wire. |
285285
| `USE_SERVO_LIB` | disabled | Use of PCA9685 normally disables use of regular servo library. You can force additional using of regular servo library by defining `USE_SERVO_LIB`. See [below](https://github.com/ArminJo/ServoEasing?tab=readme-ov-file#using-pca9685-16-channel-servo-expander). |
286+
| `USE_USER_PROVIDED_SERVO_LIB` | disabled | If you have a different servo implementation, e.g. this [M5Stack Servo expander](https://shop.m5stack.com/products/8-channel-servo-driver-unit-stm32f030) you can provide your own servo library by activating this macro.<br/>You must also modify the line [#include <DummyServo.h>](https://github.com/ArminJo/ServoEasing/blob/master/src/ServoEasing.h#L107) in *ServoEasing.h* according to the name of your library. |
286287
| `PROVIDE_ONLY_LINEAR_MOVEMENT` | disabled | Disables all but LINEAR movement. Saves up to 1540 bytes program memory. |
287288
| `DISABLE_COMPLEX_FUNCTIONS` | disabled | Disables the SINE, CIRCULAR, BACK, ELASTIC, BOUNCE and PRECISION easings. Saves up to 1850 bytes program memory. |
288-
| `MAX_EASING_SERVOS` | 12, 16(for PCA9685) | Saves 4 byte RAM per servo. If this value is smaller than the amount of servos declared, attach() will return error and other library functions will not work as expected.<br/>Of course all *AllServos*() functions and isOneServoMoving() can't work correctly! |
289+
| `MAX_EASING_SERVOS` | 12, 16(for PCA9685) | Saves 4 byte RAM per servo. If this value is smaller than the amount of servos declared, attach() will return error and other library functions will not work as expected.<br/>Then of course all *AllServos*() functions and isOneServoMoving() also can't work correctly! |
289290
| `DISABLE_MICROS_AS_DEGREE_PARAMETER` | disabled | Disables passing also microsecond values as (target angle) parameter. Saves up to 128 bytes program memory. |
290291
| `DISABLE_MIN_AND_MAX_CONSTRAINTS` | disabled | Disables servo movement constraints. Saves 4 bytes RAM per servo but strangely enough no program memory. |
291292
| `DISABLE_PAUSE_RESUME` | disabled | Disables pause and resume functionality. Saves 5 bytes RAM per servo. |
@@ -354,6 +355,9 @@ If you **detach** a servo and then attach another one, the latter will get the i
354355
# Examples for this library
355356
[The examples](https://github.com/ArminJo/ServoEasing/blob/master/examples#servoeasing-examples) are available at File > Examples > Examples from Custom Libraries / ServoEasing.<br/>
356357

358+
## DummyServoExample
359+
This is an example for a user provided servo library, which is activated by `#define USE_USER_PROVIDED_SERVO_LIB`.
360+
357361
<br/>
358362

359363
# WOKWI online examples
@@ -436,6 +440,7 @@ This will print internal information visible in the Arduino *Serial Monitor* whi
436440
- Added functions `setEaseTo()`, `setEaseToD()`, `startEaseTo()` and `startEaseToD()` with first parameter as `unsigned int` to avoid compiler errors `call of overloaded 'startEaseTo(unsigned int...`.
437441
- Added functions read() and readMicroseconds() to be compatible to Servo library.
438442
- Added function reattach() without parameters to be used after detach().
443+
- Added `USE_USER_PROVIDED_SERVO_LIB` macro.
439444

440445
### Version 3.2.1
441446
- Renamed function `setDegreeForAllServos()` to `setIntegerDegreeForAllServos()` and added function `setFloatDegreeForAllServos()`.

examples/AsymmetricEasing/AsymmetricEasing.ino

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,11 @@ float EaseQuadraticInQuarticOut(float aPercentageOfCompletion, void * aUserDataP
8181
void setup() {
8282
pinMode(LED_BUILTIN, OUTPUT);
8383
Serial.begin(115200);
84-
#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/|| defined(SERIALUSB_PID) || defined(ARDUINO_attiny3217)
84+
while (!Serial)
85+
; // Wait for Serial to become available. Is optimized away for some cores.
86+
87+
#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/ \
88+
|| defined(SERIALUSB_PID) || defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_attiny3217)
8589
delay(4000); // To be able to connect Serial monitor after reset or power up and before first print out. Do not wait for an attached Serial Monitor!
8690
#endif
8791
// Just to know which program is running on my Arduino

examples/CatMover/CatMover.ino

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,11 @@ ServoEasing ServoVertical;
7676
void setup() {
7777
pinMode(LED_BUILTIN, OUTPUT);
7878
Serial.begin(115200);
79-
#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/|| defined(SERIALUSB_PID) || defined(ARDUINO_attiny3217)
79+
while (!Serial)
80+
; // Wait for Serial to become available. Is optimized away for some cores.
81+
82+
#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/ \
83+
|| defined(SERIALUSB_PID) || defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_attiny3217)
8084
delay(4000); // To be able to connect Serial monitor after reset or power up and before first print out. Do not wait for an attached Serial Monitor!
8185
#endif
8286
// Just to know which program is running on my Arduino

examples/ConsecutiveEasingsWithCallback/ConsecutiveEasingsWithCallback.ino

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,11 @@ void ServoTargetPositionReachedHandler(ServoEasing *aServoEasingInstance);
8888
void setup() {
8989
pinMode(LED_BUILTIN, OUTPUT);
9090
Serial.begin(115200);
91-
#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/|| defined(SERIALUSB_PID) || defined(ARDUINO_attiny3217)
91+
while (!Serial)
92+
; // Wait for Serial to become available. Is optimized away for some cores.
93+
94+
#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/ \
95+
|| defined(SERIALUSB_PID) || defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_attiny3217)
9296
delay(4000); // To be able to connect Serial monitor after reset or power up and before first print out. Do not wait for an attached Serial Monitor!
9397
#endif
9498
#if !defined(PRINT_FOR_SERIAL_PLOTTER)

examples/ContinuousRotatingServo/ContinuousRotatingServo.ino

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,11 @@ void blinkLED();
6262
void setup() {
6363
pinMode(LED_BUILTIN, OUTPUT);
6464
Serial.begin(115200);
65-
#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/|| defined(SERIALUSB_PID) || defined(ARDUINO_attiny3217)
65+
while (!Serial)
66+
; // Wait for Serial to become available. Is optimized away for some cores.
67+
68+
#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/ \
69+
|| defined(SERIALUSB_PID) || defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_attiny3217)
6670
delay(4000); // To be able to connect Serial monitor after reset or power up and before first print out. Do not wait for an attached Serial Monitor!
6771
#endif
6872
// Just to know which program is running on my Arduino
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* DummyServo.cpp
3+
*
4+
* Dummy servo library as example for a user provided servo library,
5+
* which is activated by #define USE_USER_PROVIDED_SERVO_LIB.
6+
*
7+
* Copyright (C) 2024 Armin Joachimsmeyer
8+
9+
*
10+
* This file is part of ServoEasing https://github.com/ArminJo/ServoEasing.
11+
*
12+
* ServoEasing is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU General Public License as published by
14+
* the Free Software Foundation, either version 3 of the License, or
15+
* (at your option) any later version.
16+
*
17+
* This program is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20+
* See the GNU General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU General Public License
23+
* along with this program. If not, see <http://www.gnu.org/licenses/gpl.html>.
24+
*/
25+
26+
/*
27+
* We only need to implement:
28+
* Servo - Class for manipulating servo motors connected to Arduino pins.
29+
* attach(pin, min, max) - Attaches to a pin setting min and max values in microseconds
30+
* writeMicroseconds(value) - Sets the servo pulse width in microseconds
31+
* detach() - Stops an attached servo from pulsing its i/o pin.
32+
*/
33+
34+
#include <Arduino.h>
35+
#include "DummyServo.h"
36+
37+
Servo::Servo() {
38+
}
39+
40+
uint8_t Servo::attach(int pin, int min, int max) {
41+
Serial.print(F("Called attach("));
42+
Serial.print(pin);
43+
Serial.print(F(", "));
44+
Serial.print(min);
45+
Serial.print(F(", "));
46+
Serial.print(max);
47+
Serial.println(')');
48+
return pin;
49+
}
50+
51+
void Servo::detach() {
52+
Serial.println(F("Called detach()"));
53+
}
54+
void Servo::writeMicroseconds(int value) {
55+
Serial.print(F("Called writeMicroseconds("));
56+
Serial.print(value);
57+
Serial.println(')');
58+
}
59+

0 commit comments

Comments
 (0)