https://github.com/arminjo/lightweightservo
Lightweight Servo library for Arduino for 2 Servos at Pin 9 and 10. Needs only timer1, no interrupts or other resources.
https://github.com/arminjo/lightweightservo
arduino-library servo
Last synced: 5 months ago
JSON representation
Lightweight Servo library for Arduino for 2 Servos at Pin 9 and 10. Needs only timer1, no interrupts or other resources.
- Host: GitHub
- URL: https://github.com/arminjo/lightweightservo
- Owner: ArminJo
- License: gpl-3.0
- Created: 2019-01-03T19:02:31.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2024-10-25T18:15:51.000Z (almost 2 years ago)
- Last Synced: 2025-10-07T01:20:54.298Z (10 months ago)
- Topics: arduino-library, servo
- Language: C++
- Homepage:
- Size: 42 KB
- Stars: 9
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# [LightweightServo](https://github.com/ArminJo/LightweightServo)
[](https://www.gnu.org/licenses/gpl-3.0)
[](https://github.com/ArminJo/LightweightServo/releases/latest)
[](https://github.com/ArminJo/LightweightServo/commits/master)
[](https://github.com/ArminJo/LightweightServo/actions)

[](https://stand-with-ukraine.pp.ua)
Part of the Arduino library [ServoEasing](https://github.com/ArminJo/ServoEasing)
[](https://github.com/ArminJo/LightweightServo?tab=readme-ov-file#revision-history)
#### If you find this library useful, please give it a star.
🌎 [Google Translate](https://translate.google.com/translate?sl=en&u=https://github.com/ArminJo/LightweightServo)
## Small servo library for Arduino
This library is contained in the Arduino [SevoEasing](https://github.com/ArminJo/ServoEasing) library.
* Comparable to [Adafruit_TiCoServo library](https://github.com/adafruit/Adafruit_TiCoServo).
* No problems with **servo twitching**.
* Enables use of NeoPixels, SoftwareSerial, and DmxSimple together with servos in the same Arduino sketch.
* LightweightServo implementation **only for pin 9 and 10** of Arduino Uno, Nano etc..
* Only timer1 hardware and **no interrupts or other overhead** used.
* Provides **auto initialization**.
* Supports F_CPU of 16, 8, 4, 2, 1 MHz.
* **Save up to 600 bytes program size** / 40 bytes RAM including auto initialization compared to Arduino Servo library.
* 8 bytes for each call to `write9()` or `write10()`.
## Usage
As simple as this:
```c++
#include "LightweightServo.hpp"
void setup() {
// no initialization required for LightweightServo :-)
// or use manual initialization (and compiler macro "DISABLE_SERVO_TIMER_AUTO_INITIALIZE") to save additional 60 bytes program memory
// initLightweightServoPin9();
}
void loop() {
write9(0);
delay(1000);
write9(180);
delay(1000);
}
```
# [API](https://github.com/ArminJo/LightweightServo/blob/master/src/LightweightServo.h#L42)
# Compile options / macros for this library
To customize the library to different requirements, there are some compile options / macros available.
Most macros must be defined in your program before the line `#include ` to take effect.
Modify them by enabling / disabling them, or change the values if applicable.
| Name | Default value | Description |
|-|-:|-|
| `DISABLE_SERVO_TIMER_AUTO_INITIALIZE` | disabled | Saves up to 60 bytes flash memory. You must then use the init function `initLightweightServoPin9And10()` or `initLightweightServoPin9_10()` manually. |