ESP32 PWM, SERVO and TONE Library 4.2.0
- Added tone control function, non-blocking
- Updated documentation and example
- ESP32_ServoSweep_NonBlockingTone_Fade.ino
This allows using a simpler driver for higher voltage servo control.
Optimized write functions with improved performance
Dual Servo Sweep with independent speed controls.
In this example, the strategy used to control servo speed is by changing the position value by smaller amounts for decreasing speed and larger amounts for increasing speed. The loop timing remains consistent.
Just 2 easing parameters (speed and easing constant) for unlimited control ...
pwm.writeServo(servoPin1, pos1, speed1, 0.0); // move 90 deg, 70 deg/s, linear
pwm.writeServo(servoPin2, pos2, speed2, 0.6); // mpve 180 deg, 140 deg/s, avg sigmoid
pwm.writeServo(servoPin3, pos3, speed3, 0.8); // move 90 deg, 180 deg/s, steep sigmoid
Servo_Easing_Time
3 servos with different easing constants and timed position control
Servo_Easing_Position
3 servos with different easing constants and position feedback control
Very smooooth servo easing and speed control...
Now you can easily use code written for the Servo Library for Arduino.
Both libraries use the same header filename: Servo.h
Methods in both libraries have identical names.
With the Servo Library for Arduino, each servo is instantiated, whereas only one instance is used with the ESP32 ESP32S2 AnalogWrite library to control up to 16 servos. Therefore, the write() method in the ESP32 ESP32S2 AnalogWrite library has a pin parameter to select the attached servo.
Superscript values represent the number of available overload functions .
With the ESP32 ESP32S2 AnalogWrite library, both Servo.h and pwmWrite.h have access to all methods. Choose one header only that best suits your application. Note that Servo.huses a Servo class that translates method names to match the Servo Library for Arduino. Each header gives full access to the libraries features.
| Library: | Servo Library for Arduino | ESP32 ESP32S2 AnalogWrite | ESP32 ESP32S2 AnalogWrite |
|---|---|---|---|
| Header | Servo.h | Servo.h | pwmWrite.h |
| Includes | ServoTimers.h | pwmWrite.h | driver/ledc.h |
| Methods | attach() 2 | attach() 10 | attachServo() 10 |
| write() | write() 2 | writeServo() 2 | |
| writeMicroseconds() | writeMicroseconds() | n/a | |
| read() | read() | read() | |
| attached() | attached() | attached() | |
| detach() | detach() | detach() | |
| attachedPin() | attachedPin() | attachedPin() | |
| readMicroseconds() | readMicroseconds() | readMicroseconds() | |
| attachPwm() 2 | attach() 2 | ||
| attachInvert() 2 | attachInvert() 2 | ||
| writePwm() 4 | write() 4 | ||
| detached() | detached() | ||
| firstFreeCh() | firstFreeCh() | ||
| pause() | pause() | ||
| resume() | resume() | ||
| printDebug() | printDebug() | ||
| setFrequency() | setFrequency() | ||
| setResolution() | setResolution() | ||
| tone() | tone() | ||
| note() | note() |