diff --git a/README.md b/README.md
index 8f4dd2b..7aa0804 100644
--- a/README.md
+++ b/README.md
@@ -2,87 +2,135 @@
[![arduino-library-badge](https://www.ardu-badge.com/badge/ESP32%20ESP32S2%20AnalogWrite.svg?)](https://www.ardu-badge.com/ESP32%20ESP32S2%20AnalogWrite)
-![image](https://user-images.githubusercontent.com/63488701/207152696-7162de8e-bea7-4353-9ae3-682bc40c4e68.png)
+
+
+Comparison to 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.
+
+#### Comparison Table
+
+- 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.h`uses 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](https://github.com/arduino-libraries/Servo) | [ESP32 ESP32S2 AnalogWrite](https://github.com/Dlloydev/ESP32-ESP32S2-AnalogWrite) | [ESP32 ESP32S2 AnalogWrite](https://github.com/Dlloydev/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() |
+| | | writePwm() 4 | write() 4 |
+| | | detached() | detached() |
+| | | attachInvert() | attachInvert() |
+| | | firstFreeCh() | firstFreeCh() |
+| | | pause() | pause() |
+| | | resume() | resume() |
+| | | printDebug() | printDebug() |
+| | | setFrequency() | setFrequency() |
+| | | setResolution() | setResolution() |
+| | | tone() | tone() |
+| | | note() | note() |
+
+
+
+![image](https://github.com/Dlloydev/jtag2updi/assets/63488701/8217e847-b427-4b2b-9f39-f941578af63d)
### Description
-This library wraps the ESP32 Arduino framework's [ledc](https://github.com/espressif/arduino-esp32/blob/master/cores/esp32/esp32-hal-ledc.c) functions and provides up to 16 PWM channels. Includes smart GPIO pin management where any pin will not be automatically configured if it has been previously accessed by other code. Some advanced control features are auto or manual pin to channel attaching and timer pause and resume methods.
+This library uses the ESP32 Arduino framework's [ledc](https://github.com/espressif/arduino-esp32/blob/master/cores/esp32/esp32-hal-ledc.c) functions and provides up to 16 channels for servos, pwm, leds, buzzers etc. Includes smart GPIO pin management where any pin will not be automatically attached if previously accessed by other code. Includes advanced control methods like timer pause/resume, phase delay using hpoint, inverted pwm and tunable servo easing.
-PWM can be inverted, phase shifted and asynchronously aligned with the timing of other pwm channels.
+Servo Easing is fully integrated into the servo write and attach functions. Only 2 parameters give complete control over the speed and the easing characteristic of the servo. The method used for easing is a [Normalized Tunable Sigmoid](https://www.desmos.com/calculator/ejkcwglzd1) ([reference](https://dhemery.github.io/DHE-Modules/technical/sigmoid/)).
-Servo Easing is fully integrated into the servo write and attach functions. Only 2 parameters give complete control over the speed and the easing characteristic of the servo. The method used for easing is a [Normalized Tunable Sigmoid](https://www.desmos.com/calculator/ejkcwglzd1) ([reference](https://dhemery.github.io/DHE-Modules/technical/sigmoid/)). An optionally inverted servo pwm feature allows using a simple NPN or N-Channel MOSFET driver for the servo's control signal.
-### Arduino core for the ESP32, ESP32-S2, ESP32-S3 and ESP32-C3
+
+#### Arduino core for the ESP32, ESP32-S2, ESP32-S3 and ESP32-C3
Recommend using the [latest release](https://github.com/espressif/arduino-esp32), however this library works with release 2.0.7 or newer.
-#### Servo Easing
+
+
+Servo Easing
Just 2 easing parameters (speed and easing constant) for unlimited control ...
```c++
-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
+myservo.write(servoPin1, pos1, speed1, 0.0); // move 90 deg at 70 deg/s, linear
+myservo.write(servoPin2, pos2, speed2, 0.6); // mpve 180 deg at 140 deg/s, avg sigmoid
+myservo.write(servoPin3, pos3, speed3, 0.8); // move 90 deg at 180 deg/s, steep sigmoid
```
#### ![ServoEasing](https://user-images.githubusercontent.com/63488701/227943891-87cb7555-fe56-4064-a83a-38b99ad58e1d.gif)
-##### Speed Control:
+#### Speed Control:
The maximum speed in degrees/sec is derived from the servo's datasheet. For this [SG90 Micro Servo](https://robojax.com/learn/arduino/robojax-servo-sg90_datasheet.pdf) we have Operating speed: 0.1 s/60 degree. In this case, the maximum value for the speed parameter is 600 deg/sec. When a new servo position value is set, the operating time in milliseconds = degrees to move / speed * 1000.
-##### Easing Control:
+#### Easing Control:
The easing constant ke controls how the servo moves to the set position by varying the speed. Its effect from linear (ke = 0.0) to maximum steep curve (ke = 0.99).
-##### Position Feedback:
+#### Position Feedback:
The calculated position of the servo is the returned value "ye" of the writeServo function. The easing position ye is normalized (0.0-1.0) but can slightly over/undershoot this range. The servo has reached its programmed position when ye = 1.0 if the new setting is larger than previous and also when ye = 0.0 if the new position setting is smaller than previous.
-##### servoWrite:
+#### servoWrite:
+
+After a new servo position is programmed, repeatedly call the servoWrite function with the same parameters until the servo completes its motion (returned value ye = 1.0 or 0.0). The servo responds according to ke and speed. Servo position is incremented after each call.
-When a new servo position is programmed, the servoWrite function is repeatedly called with the same parameters until the servo completes its motion (returned value ye = 1.0 or 0.0). The servo responds on its own according to ke and speed. Stepping of position is not required.
+
-##### **Examples:**
+
-- [![Wokwi_badge](https://user-images.githubusercontent.com/63488701/212449119-a8510897-c860-4545-8c1a-794169547ba1.svg)](https://wokwi.com/projects/364791981216008193) [Servo_Easing_Interrupt](https://github.com/Dlloydev/ESP32-ESP32S2-AnalogWrite/blob/main/examples/ESP32_C3_Interrupt_Servo_Ease_Speed/ESP32_C3_Interrupt_Servo_Ease_Speed.ino) Servo Easing with feedback based on position and Interrupt controlled sampling
+Examples
-- [![Wokwi_badge](https://user-images.githubusercontent.com/63488701/212449119-a8510897-c860-4545-8c1a-794169547ba1.svg)](https://wokwi.com/projects/361237697368753153) [Servo_Easing_Position](https://github.com/Dlloydev/ESP32-ESP32S2-AnalogWrite/blob/main/examples/Servo_Easing_Position/Servo_Easing_Position.ino) 3 servos with different easing constants and position feedback control
+[![Wokwi_badge](https://user-images.githubusercontent.com/63488701/212449119-a8510897-c860-4545-8c1a-794169547ba1.svg)](https://wokwi.com/projects/351231798778266200) [Note Explorer ♩ ♪ ♫ ♬](https://github.com/Dlloydev/ESP32-ESP32S2-AnalogWrite/blob/main/examples/Note_Explorer/Note_Explorer.ino) Plays all 96 ledc notes that are available, non blocking
-- [![Wokwi_badge](https://user-images.githubusercontent.com/63488701/212449119-a8510897-c860-4545-8c1a-794169547ba1.svg)](https://wokwi.com/projects/360276061783595009) [Servo_Easing_Time](https://github.com/Dlloydev/ESP32-ESP32S2-AnalogWrite/blob/main/examples/Servo_Easing_Time/Servo_Easing_Time.ino) 3 servos with different easing constants and timed position control
+[![Wokwi_badge](https://user-images.githubusercontent.com/63488701/212449119-a8510897-c860-4545-8c1a-794169547ba1.svg)](https://wokwi.com/projects/351175246893548120) [Note_Player](https://github.com/Dlloydev/ESP32-ESP32S2-AnalogWrite/blob/main/examples/Note_Player/Note_Player.ino) Playing Notes based on sliding pot position, 4th octave, non blocking
-- [![Wokwi_badge](https://user-images.githubusercontent.com/63488701/212449119-a8510897-c860-4545-8c1a-794169547ba1.svg)](https://wokwi.com/projects/355852275661848577) [ESP32_C3_6_Servo_Knob](https://github.com/Dlloydev/ESP32-ESP32S2-AnalogWrite/blob/main/examples/ESP32_C3_6_Servo_Knob/ESP32_C3_6_Servo_Knob.ino) Potentiometer control of 6 servos on an ESP32-C3
+[![Wokwi_badge](https://user-images.githubusercontent.com/63488701/212449119-a8510897-c860-4545-8c1a-794169547ba1.svg)](https://wokwi.com/projects/349336125753524820) [Pwm_3phase_40kHz](https://github.com/Dlloydev/ESP32-ESP32S2-AnalogWrite/blob/main/examples/Pwm_3phase_40kHz/Pwm_3phase_40kHz.ino) ESP32 3 Phase PWM Outputs (40kHz, 10-bit)
-- [![Wokwi_badge](https://user-images.githubusercontent.com/63488701/212449119-a8510897-c860-4545-8c1a-794169547ba1.svg)](https://wokwi.com/projects/349232255258853970) [16 PWM Fade](https://github.com/Dlloydev/ESP32-ESP32S2-AnalogWrite/blob/main/examples/ESP32_Fade16/ESP32_Fade16.ino) ESP32 fading 16 pairs of LEDs
+[![Wokwi_badge](https://user-images.githubusercontent.com/63488701/212449119-a8510897-c860-4545-8c1a-794169547ba1.svg)](https://wokwi.com/projects/334722465700774482) [Pwm_ESP32_3phase_10kHz](https://github.com/Dlloydev/ESP32-ESP32S2-AnalogWrite/blob/main/examples/Pwm_ESP32_3phase_10kHz/Pwm_ESP32_3phase_10kHz.ino) ESP32 3 Phase PWM Outputs (10kHz, 10-bit)
-- [![Wokwi_badge](https://user-images.githubusercontent.com/63488701/212449119-a8510897-c860-4545-8c1a-794169547ba1.svg)](https://wokwi.com/projects/349978851105833554) [14 PWM Fade 2 Servo](https://github.com/Dlloydev/ESP32-ESP32S2-AnalogWrite/blob/main/examples/ESP32_Fade_Servo/ESP32_Fade_Servo.ino) ESP32 fading 14 pairs of LEDs and controlling 2 servo motors
+[![Wokwi_badge](https://user-images.githubusercontent.com/63488701/212449119-a8510897-c860-4545-8c1a-794169547ba1.svg)](https://wokwi.com/projects/334856585002091092) [Pwm_ESP32_C3_3phase_10kHz](https://github.com/Dlloydev/ESP32-ESP32S2-AnalogWrite/blob/main/examples/Pwm_ESP32_C3_3phase_10kHz/Pwm_ESP32_C3_3phase_10kHz.ino) ESP32 C3 3 Phase PWM Outputs (10kHz, 10-bit)
-- [![Wokwi_badge](https://user-images.githubusercontent.com/63488701/212449119-a8510897-c860-4545-8c1a-794169547ba1.svg)](https://wokwi.com/projects/350037178957431378) [Servo Sweep](https://github.com/Dlloydev/ESP32-ESP32S2-AnalogWrite/blob/main/examples/Servo_Sweep/Servo_Sweep.ino) Sweep a servo motor from 0-180 degrees and back
+[![Wokwi_badge](https://user-images.githubusercontent.com/63488701/212449119-a8510897-c860-4545-8c1a-794169547ba1.svg)](https://wokwi.com/projects/334765722024542804) [Pwm_ESP32_S2_3phase_10kHz](https://github.com/Dlloydev/ESP32-ESP32S2-AnalogWrite/blob/main/examples/Pwm_ESP32_S2_3phase_10kHz/Pwm_ESP32_S2_3phase_10kHz.ino) ESP32 S2 3 Phase PWM Outputs (10kHz, 10-bit)
-- [![Wokwi_badge](https://user-images.githubusercontent.com/63488701/212449119-a8510897-c860-4545-8c1a-794169547ba1.svg)](https://wokwi.com/projects/351967394028061269) [Servo_Sweep_Inverted](https://github.com/Dlloydev/ESP32-ESP32S2-AnalogWrite/blob/main/examples/Servo_Sweep_Inverted/Servo_Sweep_Inverted.ino) Using inverted PWM mode to sweep a servo motor
+[![Wokwi_badge](https://user-images.githubusercontent.com/63488701/212449119-a8510897-c860-4545-8c1a-794169547ba1.svg)](https://wokwi.com/projects/349978851105833554) [Pwm_Fade_Servo](https://github.com/Dlloydev/ESP32-ESP32S2-AnalogWrite/blob/main/examples/Pwm_Fade_Servo/Pwm_Fade_Servo) ESP32 fading 14 pairs of LEDs and controlling 2 servo motors
-- [![Wokwi_badge](https://user-images.githubusercontent.com/63488701/212449119-a8510897-c860-4545-8c1a-794169547ba1.svg)](https://wokwi.com/projects/351978833396630095) [Dual Servo Sweep with Independent Speed Control](https://github.com/Dlloydev/ESP32-ESP32S2-AnalogWrite/blob/main/examples/Dual_Servo_Sweep_Speed/Dual_Servo_Sweep_Speed.ino)
+[![Wokwi_badge](https://user-images.githubusercontent.com/63488701/212449119-a8510897-c860-4545-8c1a-794169547ba1.svg)](https://wokwi.com/projects/349232255258853970) [Pwm_Fade16](https://github.com/Dlloydev/ESP32-ESP32S2-AnalogWrite/blob/main/examples/Pwm_Fade16/Pwm_Fade16.ino) ESP32 fading 16 pairs of LEDs
-- [![Wokwi_badge](https://user-images.githubusercontent.com/63488701/212449119-a8510897-c860-4545-8c1a-794169547ba1.svg)](https://wokwi.com/projects/350033311963284051) [Servo Knob](https://github.com/Dlloydev/ESP32-ESP32S2-AnalogWrite/blob/main/examples/Servo_Knob/Servo_Knob.ino) Controls servo position by using a potentiometer
+[![Wokwi_badge](https://user-images.githubusercontent.com/63488701/212449119-a8510897-c860-4545-8c1a-794169547ba1.svg)](https://wokwi.com/projects/349322326995632722) [Pwm_Sync2_300kHz](https://github.com/Dlloydev/ESP32-ESP32S2-AnalogWrite/blob/main/examples/Pwm_Sync2_300kHz/Pwm_Sync2_300kHz.ino) 2 synchronized PWM outputs using the same timer (channel pair)
-- [![Wokwi_badge](https://user-images.githubusercontent.com/63488701/212449119-a8510897-c860-4545-8c1a-794169547ba1.svg)](https://wokwi.com/projects/351231798778266200) [Note Explorer ♩ ♪ ♫ ♬](https://github.com/Dlloydev/ESP32-ESP32S2-AnalogWrite/blob/main/examples/ESP32_Note_Explorer/ESP32_Note_Explorer.ino) Plays all 96 ledc notes that are available, non blocking
+[![Wokwi_badge](https://user-images.githubusercontent.com/63488701/212449119-a8510897-c860-4545-8c1a-794169547ba1.svg)](https://wokwi.com/projects/364791981216008193) [Servo_Easing_Interrupt](https://github.com/Dlloydev/ESP32-ESP32S2-AnalogWrite/blob/main/examples/Servo_Easing_Interrupt/Servo_Easing_Interrupt.ino) Servo Easing with position feedback and Interrupt control
-- [![Wokwi_badge](https://user-images.githubusercontent.com/63488701/212449119-a8510897-c860-4545-8c1a-794169547ba1.svg)](https://wokwi.com/projects/351175246893548120) [Playing Notes](https://github.com/Dlloydev/ESP32-ESP32S2-AnalogWrite/blob/main/examples/playingNotes/playingNotes.ino) Playing Notes based on sliding pot position, 4th octave, non blocking
+[![Wokwi_badge](https://user-images.githubusercontent.com/63488701/212449119-a8510897-c860-4545-8c1a-794169547ba1.svg)](https://wokwi.com/projects/361237697368753153) [Servo_Easing_Position](https://github.com/Dlloydev/ESP32-ESP32S2-AnalogWrite/blob/main/examples/Servo_Easing_Position/Servo_Easing_Position.ino) 3 servos with easing and position feedback control
-- [![Wokwi_badge](https://user-images.githubusercontent.com/63488701/212449119-a8510897-c860-4545-8c1a-794169547ba1.svg)](https://wokwi.com/projects/352178590336932865) [Playing Tones](https://github.com/Dlloydev/ESP32-ESP32S2-AnalogWrite/blob/main/examples/playingTones/playingTones.ino) Playing Tones based on sliding pot position, 4Hz to 4095Hz, non blocking
+[![Wokwi_badge](https://user-images.githubusercontent.com/63488701/212449119-a8510897-c860-4545-8c1a-794169547ba1.svg)](https://wokwi.com/projects/350033311963284051) [Servo Knob](https://github.com/Dlloydev/ESP32-ESP32S2-AnalogWrite/blob/main/examples/Servo_Knob/Servo_Knob.ino) Controls servo position by using a potentiometer
-- [![Wokwi_badge](https://user-images.githubusercontent.com/63488701/212449119-a8510897-c860-4545-8c1a-794169547ba1.svg)](https://wokwi.com/projects/349322326995632722) [2 Sync 300kHz](https://github.com/Dlloydev/ESP32-ESP32S2-AnalogWrite/blob/main/examples/ESP32_Sync2_300kHz/ESP32_Sync2_300kHz.ino) 2 synchronized PWM outputs using the same timer (channel pair)
+[![Wokwi_badge](https://user-images.githubusercontent.com/63488701/212449119-a8510897-c860-4545-8c1a-794169547ba1.svg)](https://wokwi.com/projects/355852275661848577) [Servo_Knob_Six](https://github.com/Dlloydev/ESP32-ESP32S2-AnalogWrite/blob/main/examples/Servo_Knob_Six/Servo_Knob_Six.ino) Potentiometer control of 6 servos on an ESP32-C3
-- [![Wokwi_badge](https://user-images.githubusercontent.com/63488701/212449119-a8510897-c860-4545-8c1a-794169547ba1.svg)](https://wokwi.com/projects/349336125753524820) [ESP32_3-Phase 40kHz](https://github.com/Dlloydev/ESP32-ESP32S2-AnalogWrite/blob/main/examples/ESP32_3phase_40kHz/ESP32_3phase_40kHz.ino) ESP32 3 Phase PWM Outputs (40kHz, 10-bit)
+[![Wokwi_badge](https://user-images.githubusercontent.com/63488701/212449119-a8510897-c860-4545-8c1a-794169547ba1.svg)](https://wokwi.com/projects/350037178957431378) [Servo Sweep](https://github.com/Dlloydev/ESP32-ESP32S2-AnalogWrite/blob/main/examples/Servo_Sweep/Servo_Sweep.ino) Sweep a servo motor from 0-180 degrees and back
-- [![Wokwi_badge](https://user-images.githubusercontent.com/63488701/212449119-a8510897-c860-4545-8c1a-794169547ba1.svg)](https://wokwi.com/projects/334722465700774482) [ESP32_3-Phase 10kHz](https://github.com/Dlloydev/ESP32-ESP32S2-AnalogWrite/blob/main/examples/ESP32_3phase_10kHz/ESP32_3phase_10kHz.ino) ESP32 3 Phase PWM Outputs (10kHz, 10-bit)
+[![Wokwi_badge](https://user-images.githubusercontent.com/63488701/212449119-a8510897-c860-4545-8c1a-794169547ba1.svg)](https://wokwi.com/projects/351967394028061269) [Servo_Sweep_Inverted](https://github.com/Dlloydev/ESP32-ESP32S2-AnalogWrite/blob/main/examples/Servo_Sweep_Inverted/Servo_Sweep_Inverted.ino) Using inverted PWM mode to sweep a servo motor
-- [![Wokwi_badge](https://user-images.githubusercontent.com/63488701/212449119-a8510897-c860-4545-8c1a-794169547ba1.svg)](https://wokwi.com/projects/334765722024542804) [ESP32_S2_3-Phase_10kHz](https://github.com/Dlloydev/ESP32-ESP32S2-AnalogWrite/blob/main/examples/ESP32_S2_3phase_10kHz/ESP32_S2_3phase_10kHz.ino) ESP32 S2 3 Phase PWM Outputs (10kHz, 10-bit)
+[![Wokwi_badge](https://user-images.githubusercontent.com/63488701/212449119-a8510897-c860-4545-8c1a-794169547ba1.svg)](https://wokwi.com/projects/351978833396630095) [Servo_Sweep_Speed](https://github.com/Dlloydev/ESP32-ESP32S2-AnalogWrite/blob/main/examples/Servo_Sweep_Speed/Servo_Sweep_Speed.ino) Independent speed control of 2 servos
-- [![Wokwi_badge](https://user-images.githubusercontent.com/63488701/212449119-a8510897-c860-4545-8c1a-794169547ba1.svg)](https://wokwi.com/projects/334856585002091092) [ESP32_C3_3-Phase_10kHz](https://github.com/Dlloydev/ESP32-ESP32S2-AnalogWrite/blob/main/examples/ESP32_C3_3phase_10kHz/ESP32_C3_3phase_10kHz.ino) ESP32 C3 3 Phase PWM Outputs (10kHz, 10-bit)
+[![Wokwi_badge](https://user-images.githubusercontent.com/63488701/212449119-a8510897-c860-4545-8c1a-794169547ba1.svg)](https://wokwi.com/projects/352178590336932865) [Tone_Player](https://github.com/Dlloydev/ESP32-ESP32S2-AnalogWrite/blob/main/examples/Tone_Player/Tone_Player.ino) Playing Tones based on sliding pot position
-
+
+
+
+
+PWM Channel Configuration
| Board | PWM Pins | PWM, Duty and Phase Channels | Frequency and Resolution Channels |
| ----------- | ------------------------- | ---------------------------- | --------------------------------- |
@@ -90,8 +138,6 @@ When a new servo position is programmed, the servoWrite function is repeatedly c
| ESP32‑S2/S3 | 0-21, 26, 33-45 | 8 | 4 |
| ESP32‑C3 | 0- 10, 18-21 | 6 | 3 |
-### PWM Channel Configuration
-
Frequency and resolution values are shared by each channel pair thats on the same timer. When any channel gets configured, the next lower or higher channel gets updated with the same frequency and resolution values as appropriate.
| PWM Channel | Speed Mode | Timer | Frequency | Resolution | Duty | Phase |
@@ -113,38 +159,20 @@ Frequency and resolution values are shared by each channel pair thats on the sam
| 14 | 1 | 3 | 8 | 8 | 15 | 15 |
| 15 | 1 | 3 | 8 | 8 | 16 | 16 |
+
+## Reference (Servo.h)
-### write()
-
-##### Description
-
-This function writes the duty and optionally the frequency, resolution and phase parameters. If necessary, the pin will be automatically attached to the first available pwm channel. To avoid conflicts with other code, the pin will not be attached if previously accessed.
-
-##### Syntax
+### Include and Instantiate
```c++
-pwm.write(pin, duty)
-pwm.write(pin, duty, frequency)
-pwm.write(pin, duty, frequency, resolution)
-pwm.write(pin, duty, frequency, resolution, phase)
+#include
+Servo myservo = Servo();
```
-##### Parameters
-
-- **pin** The pin number which (if necessary) will be attached to the next free channel *(uint8_t)*
-- **duty** This sets the pwm duty. The range is 0 to (2**resolution) - 1 *(uint32_t)*
-- **frequency** The pwm timer frequency (Hz). The frequency and resolution limits are interdependent *(uint32_t)*. For more details, see [Supported Range of Frequency and Duty Resolutions](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/ledc.html#ledc-api-supported-range-frequency-duty-resolution).
-- **resolution** The bit resolution of the pwm duty *(uint8_t)*
-- **phase** This is also referred to as the **hpoint** value, which is the timer/counter value that the pwm output turns on. The useable range is the same as for the duty parameter. This can be used to phase shift the output or for synchronization. When the phase parameter is used, the pwm output will initiate in a paused state to allow synchronization *(uint32_t)*
-
-##### Returns
-
-The set frequency *(float)*
-
+
-
-### writeServo()
+write()
##### Description:
@@ -178,8 +206,8 @@ This process is automatic - the servo pin will be attached to the next free chan
##### Syntax
```c++
-pwm.writeServo(pin, value)
-pwm.writeServo(pin, value, speed, ke)
+myservo.write(pin, value)
+myservo.write(pin, value, speed, ke)
```
##### Parameters
@@ -194,77 +222,35 @@ pwm.writeServo(pin, value, speed, ke)
- If the servo easing constant `ke` is 1.0 (default) then the pwm duty value *(uint32_t)* is returned.
- If `ke` is less than 1.0, then a normalized float value (0.0 to 1.0) is returned. This represents the programmed servo position from start to stop as it moves over time. When the returned value reaches 0.5, this represents both 50% travel and 50% time duration, no matter what easing constant is set.
+
+
-### tone()
-
-##### Description:
-
-This function generates a square wave of the specified frequency (and 50% duty cycle and 8-bit resolution) on a pin. There will be no output (no tone) if the duration isn't specified or equals 0. The duration in milliseconds has range 0-65535 where 0 is off and 65535 is always on. The last parameter (interval) specifies the pause time before the next call to tone becomes ready. The pin can be connected to a piezo buzzer or other speaker to play tones.
-
-**Channel Pairing**
-
-The frequency and resolution values are shared by each channel pair. When the tone pin is attached, the next lower or higher channel on the same timer gets updated with the same frequency and resolution values as appropriate.
-
-**Attaching to free Channel**
+writeMicroseconds()
-This process is automatic - the tone pin will be attached to the next free channel. If you need to assign the tone pin to a specific channel, then call the `attach()`method first.
-
-##### Syntax
-
-```c++
-pwm.tone(pin, frequency, duration)
-pwm.tone(pin, frequency, duration, interval)
-```
-
-##### Parameters
-
-- **pin** The pin number which (if necessary) will be attached to the next free channel *(uint8_t)*
-- **frequency** The tone frequency (Hz) with range 1-65535 *(uint16_t)*.
-- **duration** The duration in milliseconds with range 0-65535 *(uint16_t)*, where 0 is off (default) and 65535 is always on.
-- **interval** This optional parameter specifies the pause time in milliseconds before the next call to tone becomes ready. *(uint16_t)*, range 0-65535, default = 0.
-
-##### Returns
-
-- nothing
-
-
-
-### note()
-
-##### Description:
-
-This function generates a square wave of the specified frequency (and 50% duty cycle and 8-bit resolution) on a pin. There will be no output (no tone) if the duration isn't specified or equals 0. The duration in milliseconds has range 0-65535 where 0 is off and 65535 is always on. The last parameter (interval) specifies the pause time before the next call to note becomes ready. The pin can be connected to a piezo buzzer or other speaker to play notes.
-
-**Channel Pairing**
-
-The frequency and resolution values are shared by each channel pair. When the note pin is attached, the next lower or higher channel on the same timer gets updated with the same frequency and resolution values as appropriate.
-
-**Attaching to free Channel**
+##### Description
-This process is automatic - the note pin will be attached to the next free channel. If you need to assign the tone pin to a specific channel, then call the `attach()`method first.
+This function calls the write() function above.
-##### Syntax
+**Syntax**
```c++
-pwm.note(pin, note, octave, duration, interval)
+myservo.writeMicroseconds()
```
##### Parameters
-- **pin** The pin number which (if necessary) will be attached to the next free channel *(uint8_t)*
-- **note** The type is defined in [esp32-hal-ledc.h](https://github.com/espressif/arduino-esp32/blob/master/cores/esp32/esp32-hal-ledc.h) *(note_t)*.
-- **octave** There are 8 octaves available, 1 to 8 *(uint8_t)*
-- **duration** The duration in milliseconds with range 0-65535 *(uint16_t)*, where 0 is off (default) and 65535 is always on.
-- **interval** This parameter specifies the pause time in milliseconds before the next call to tone becomes ready. *(uint16_t)*, range 0-65535, default = 0.
+- none.
##### Returns
- nothing
+
+
-### read()
+read()
##### Description
@@ -273,7 +259,7 @@ Read the current angle of the servo in degrees. The returned value is *float* ty
**Syntax**
```c++
-read(pin)
+myservo.read(pin)
```
##### Parameters
@@ -284,9 +270,11 @@ read(pin)
- The angle of the servo, from 0 to 180 degrees *(float)*
+
+
-### readMicroseconds()
+readMicroseconds()
##### Description
@@ -295,7 +283,7 @@ Reads the timer channel's duty value in microseconds. The minimum limit is 544
**Syntax**
```c++
-readMicroseconds(pin)
+myservo.readMicroseconds(pin)
```
##### Parameters
@@ -306,9 +294,11 @@ readMicroseconds(pin)
- The channel's duty value converted to microseconds *(float)*
+
+
-### attach()
+attach()
##### Description
@@ -317,13 +307,16 @@ This function allows auto-attaching a pin to the first available channel if only
**Syntax**
```c++
-attach(pin) // auto attach to 1st free channel
-attach(pin, ch) // attach to specified channel
-attach(pin, minUs, maxUs) // auto attach to free ch with servo limits
-attach(pin, ch, minUs, maxUs) // attach to specified ch with servo limits
-attach(pin, minUs, maxUs, speed, ke) // attach to free ch with speed and easing constant
-attach(pin, ch, minUs, maxUs, speed, ke) // as above but attaches to specified channel
-attach(pin, ch, minUs, maxUs, speed, ke, invert) // as above with invert
+myservo.attach(pin) // auto attach to 1st free channel
+myservo.attach(pin, invert) // as above with invert
+myservo.attach(pin, ch) // attach to specified channel
+myservo.attach(pin, ch, invert) // as above with invert
+myservo.attach(pin, minUs, maxUs) // auto attach to free ch, servo limits
+myservo.attach(pin, ch, minUs, maxUs) // attach to specified ch, servo limits
+myservo.attach(pin, ch, minUs, maxUs, invert) // as above with invert
+myservo.attach(pin, minUs, maxUs, speed, ke) // attach to free ch, speed, easing const
+myservo.attach(pin, ch, minUs, maxUs, speed, ke) // as above but attaches to specified ch
+myservo.attach(pin, ch, minUs, maxUs, speed, ke, invert) // as above with invert
```
##### Parameters
@@ -353,25 +346,25 @@ attach(pin, ch, minUs, maxUs, speed, ke, invert) // as above with invert
- If attached, the channel number (0-15) *(uint8_t)*
- If not attached, 255 *(uint8_t)*
+
+
-### attachInvert()
+attached()
##### Description
-This function allows auto-attaching a pin to the first available channel if only the pin is specified. To have the pin assigned to a specific channel, use both the pin and channel (ch) parameters. The pwm output will be inverted. The duty value represents the low period.
+This function checks the pin status and if attached, returns the channel number.
**Syntax**
```c++
-attachInvert(pin); // attach pin to next free channel with inverted pwm
-attachInvert(pin, ch); // attach to specified ch with inverted pwm
+myservo.attached(pin)
```
##### Parameters
-- **pin** The pin number *(uint8_t)*
-- **ch** This optional parameter is used to attach the pin to a specific channel *(uint8_t)*)
+- **pin** The pin number *(uint8_t)
##### Returns
@@ -380,18 +373,20 @@ attachInvert(pin, ch); // attach to specified ch with inverted pwm
- If attached, the channel number (0-15) *(uint8_t)*
- If not attached, 255 *(uint8_t)*
+
+
-### attached()
+attachedPin()
##### Description
-This function checks the pin status and if attached, returns the channel number.
+This function returns the pin that's attached to the specified channel.
**Syntax**
```c++
-attached(pin)
+myservo.attachedPin(ch)
```
##### Parameters
@@ -400,37 +395,75 @@ attached(pin)
##### Returns
+- If attached, the pin number *(uint8_t)*
+- If the channel is free, 255 *(uint8_t)*
+
+
+
+
+
+attachInvert()
+
+##### Description
+
+This function allows auto-attaching a pin to the first available channel if only the pin is specified. To have the pin assigned to a specific channel, use both the pin and channel (ch) parameters. The pwm output will be inverted. The duty value represents the low period.
+
+**Syntax**
+
+```c++
+myservo.attachInvert(pin); // attach pin to next free channel with inverted pwm
+myservo.attachInvert(pin, ch); // attach to specified ch with inverted pwm
+```
+
+##### Parameters
+
+- **pin** The pin number *(uint8_t)*
+- **ch** This optional parameter is used to attach the pin to a specific channel *(uint8_t)*)
+
+##### Returns
+
- If not a valid pin, 254 *(uint8_t)*
- free channels exist, 253 *(uint8_t)*
- If attached, the channel number (0-15) *(uint8_t)*
- If not attached, 255 *(uint8_t)*
+
-### attachedPin()
+
+
+writePwm()
##### Description
-This function returns the pin that's attached to the specified channel.
+This function writes the duty and optionally the frequency, resolution and phase parameters. If necessary, the pin will be automatically attached to the first available pwm channel. To avoid conflicts with other code, the pin will not be attached if previously accessed.
-**Syntax**
+##### Syntax
```c++
-attachedPin(ch)
+myservo.writePwm(pin, duty)
+myservo.writePwm(pin, duty, frequency)
+myservo.writePwm(pin, duty, frequency, resolution)
+myservo.writePwm(pin, duty, frequency, resolution, phase)
```
##### Parameters
-- **pin** The pin number *(uint8_t)
+- **pin** The pin number which (if necessary) will be attached to the next free channel *(uint8_t)*
+- **duty** This sets the pwm duty. The range is 0 to (2**resolution) - 1 *(uint32_t)*
+- **frequency** The pwm timer frequency (Hz). The frequency and resolution limits are interdependent *(uint32_t)*. For more details, see [Supported Range of Frequency and Duty Resolutions](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/ledc.html#ledc-api-supported-range-frequency-duty-resolution).
+- **resolution** The bit resolution of the pwm duty *(uint8_t)*
+- **phase** This is also referred to as the **hpoint** value, which is the timer/counter value that the pwm output turns on. The useable range is the same as for the duty parameter. This can be used to phase shift the output or for synchronization. When the phase parameter is used, the pwm output will initiate in a paused state to allow synchronization *(uint32_t)*
##### Returns
-- If attached, the pin number *(uint8_t)*
-- If the channel is free, 255 *(uint8_t)*
+The set frequency *(float)*
+
+
-### detachPin()
+detachPin()
##### Description
@@ -439,7 +472,7 @@ This function removes control of the pin from the specified PWM channel. Also,
**Syntax**
```c++
-pwm.detachPin(pin)
+myservo.detachPin(pin)
```
##### Parameters
@@ -450,9 +483,11 @@ pwm.detachPin(pin)
- nothing
+
+
-### pause()
+pause()
##### Description
@@ -463,7 +498,7 @@ If this function is manually called, any channel(s) that get configured will hav
**Syntax**
```c++
-pwm.pause()
+myservo.pause()
```
##### Parameters
@@ -474,9 +509,11 @@ pwm.pause()
- nothing
+
+
-### resume()
+resume()
##### Description
@@ -485,7 +522,7 @@ This function is used to start the pwm outputs of all channels to synchronize (a
**Syntax**
```c++
-pwm.resume()
+myservo.resume()
```
##### Parameters
@@ -496,9 +533,11 @@ pwm.resume()
- nothing
+
+
-### setFrequency()
+setFrequency()
##### Description
@@ -507,7 +546,7 @@ Sets the PWM frequency on any PWM pin.
**Syntax**
```c++
-pwm.setFrequency(pin, frequency)
+myservo.setFrequency(pin, frequency)
```
##### Parameters
@@ -519,9 +558,11 @@ pwm.setFrequency(pin, frequency)
- The frequency set by the timer hardware *(float)*
+
+
-### setResolution()
+setResolution()
##### Description
@@ -530,7 +571,7 @@ Sets the PWM resolution for any PWM pin.
**Syntax**
```c++
-pwm.setResolution(pin, resolution)
+myservo.setResolution(pin, resolution)
```
##### Parameters
@@ -542,9 +583,83 @@ pwm.setResolution(pin, resolution)
- The set resolution reported by the pin channel *(uint8_t)*
+
+
+
+
+tone()
+
+##### Description:
+
+This function generates a square wave of the specified frequency (and 50% duty cycle and 8-bit resolution) on a pin. There will be no output (no tone) if the duration isn't specified or equals 0. The duration in milliseconds has range 0-65535 where 0 is off and 65535 is always on. The last parameter (interval) specifies the pause time before the next call to tone becomes ready. The pin can be connected to a piezo buzzer or other speaker to play tones.
+
+**Channel Pairing**
+
+The frequency and resolution values are shared by each channel pair. When the tone pin is attached, the next lower or higher channel on the same timer gets updated with the same frequency and resolution values as appropriate.
+
+**Attaching to free Channel**
+
+This process is automatic - the tone pin will be attached to the next free channel. If you need to assign the tone pin to a specific channel, then call the `attach()`method first.
+
+##### Syntax
+
+```c++
+myservo.tone(pin, frequency, duration)
+myservo.tone(pin, frequency, duration, interval)
+```
+
+##### Parameters
+
+- **pin** The pin number which (if necessary) will be attached to the next free channel *(uint8_t)*
+- **frequency** The tone frequency (Hz) with range 1-65535 *(uint16_t)*.
+- **duration** The duration in milliseconds with range 0-65535 *(uint16_t)*, where 0 is off (default) and 65535 is always on.
+- **interval** This optional parameter specifies the pause time in milliseconds before the next call to tone becomes ready. *(uint16_t)*, range 0-65535, default = 0.
+
+##### Returns
+
+- nothing
+
+
+
+
+
+note()
+
+##### Description:
+
+This function generates a square wave of the specified frequency (and 50% duty cycle and 8-bit resolution) on a pin. There will be no output (no tone) if the duration isn't specified or equals 0. The duration in milliseconds has range 0-65535 where 0 is off and 65535 is always on. The last parameter (interval) specifies the pause time before the next call to note becomes ready. The pin can be connected to a piezo buzzer or other speaker to play notes.
+
+**Channel Pairing**
+
+The frequency and resolution values are shared by each channel pair. When the note pin is attached, the next lower or higher channel on the same timer gets updated with the same frequency and resolution values as appropriate.
+
+**Attaching to free Channel**
+This process is automatic - the note pin will be attached to the next free channel. If you need to assign the tone pin to a specific channel, then call the `attach()`method first.
+
+##### Syntax
+
+```c++
+pwm.note(pin, note, octave, duration, interval)
+```
-### printDebug()
+##### Parameters
+
+- **pin** The pin number which (if necessary) will be attached to the next free channel *(uint8_t)*
+- **note** The type is defined in [esp32-hal-ledc.h](https://github.com/espressif/arduino-esp32/blob/master/cores/esp32/esp32-hal-ledc.h) *(note_t)*.
+- **octave** There are 8 octaves available, 1 to 8 *(uint8_t)*
+- **duration** The duration in milliseconds with range 0-65535 *(uint16_t)*, where 0 is off (default) and 65535 is always on.
+- **interval** This parameter specifies the pause time in milliseconds before the next call to tone becomes ready. *(uint16_t)*, range 0-65535, default = 0.
+
+##### Returns
+
+- nothing
+
+
+
+
+
+printDebug()
##### Description
@@ -553,7 +668,7 @@ This function prints the available PWM pins to choose from and a formatted outpu
**Syntax**
```c++
-pwm.printDebug()
+myservo.printDebug()
```
##### Parameters (optional)
@@ -566,7 +681,8 @@ pwm.printDebug()
![image](https://user-images.githubusercontent.com/63488701/229374511-de75b97d-f91f-44d0-b103-0ca858d16727.png)
+
+
```
This Library is licensed under the MIT License
```
-
diff --git a/Using pwmWrite.md b/Using pwmWrite.md
deleted file mode 100644
index 0eed9fa..0000000
--- a/Using pwmWrite.md
+++ /dev/null
@@ -1,60 +0,0 @@
-## Using pwm.write()
-
-Using this function is very easy as much is done transparently. Initializing a pin with `pinMode` is not required as attaching the pin to a channel and setting up the timer resource is automatic. The various parameters available are:
-
-| Parameter | Default | Description |
-| --------------- | ------- | ------------------------------------------ |
-| pin | 255 | no pin attached |
-| frequency | 1000 | pwm frequency (Hz) |
-| resolution | 8 | bit width |
-| duty | 0 | duty cycle |
-| phase | 0 | phase shift |
-| returned value: | 0 | returns configured timer frequency (float) |
-
-### Prototypes:
-
-```c++
-float write(int8_t pin, int32_t duty, float frequency, uint8_t resolution, uint32_t phase);
-float write(int8_t pin, int32_t duty, float frequency, uint8_t resolution);
-float write(int8_t pin, int32_t duty, float frequency);
-float write(int8_t pin, int32_t duty);
-```
-
-### Examples
-
-Beginning of sketch:
-
-```c++
-#include // include header file
-const byte ledPin = 5; // led connected to pin 5
-Pwm pwm = Pwm(); // create an object
-```
-
-Syntax:
-
-```c++
-pwm.write()
-```
-
-Then in setup() or loop() as desired. Unspecified parameters will be at default:
-
-```c++
-pwm.write(ledPin, 127); // 50% duty, default 1000 Hz, default 8-bit, default 0 phase shift
-```
-
-```c++
-pwm.write(ledPin, 127, 5000); // 50% duty, 5000 Hz, default 8-bit, default 0 phase shift
-```
-
-```c++
-pwm.write(ledPin, 63, 500, 8); // 25% duty, 500 Hz, 8-bit, default 0 phase shift
-```
-
-```c++
-pwm.write(ledPin, 255, 500, 10, 255); // 25% duty, 500 Hz, 10-bit, 25% phase shift
-```
-
-
-
-
-
diff --git a/examples/ESP32_Note_Explorer/ESP32_Note_Explorer.ino b/examples/Note_Explorer/Note_Explorer.ino
similarity index 100%
rename from examples/ESP32_Note_Explorer/ESP32_Note_Explorer.ino
rename to examples/Note_Explorer/Note_Explorer.ino
diff --git a/examples/playingNotes/playingNotes.ino b/examples/Note_Player/Note_Player.ino
similarity index 100%
rename from examples/playingNotes/playingNotes.ino
rename to examples/Note_Player/Note_Player.ino
diff --git a/examples/ESP32_3phase_40kHz/ESP32_3phase_40kHz.ino b/examples/Pwm_3phase_40kHz/Pwm_3phase_40kHz.ino
similarity index 100%
rename from examples/ESP32_3phase_40kHz/ESP32_3phase_40kHz.ino
rename to examples/Pwm_3phase_40kHz/Pwm_3phase_40kHz.ino
diff --git a/examples/ESP32_3phase_10kHz/ESP32_3phase_10kHz.ino b/examples/Pwm_ESP32_3phase_10kHz/Pwm_ESP32_3phase_10kHz.ino
similarity index 100%
rename from examples/ESP32_3phase_10kHz/ESP32_3phase_10kHz.ino
rename to examples/Pwm_ESP32_3phase_10kHz/Pwm_ESP32_3phase_10kHz.ino
diff --git a/examples/ESP32_C3_3phase_10kHz/ESP32_C3_3phase_10kHz.ino b/examples/Pwm_ESP32_C3_3phase_10kHz/ESP32_C3_3phase_10kHz.ino
similarity index 100%
rename from examples/ESP32_C3_3phase_10kHz/ESP32_C3_3phase_10kHz.ino
rename to examples/Pwm_ESP32_C3_3phase_10kHz/ESP32_C3_3phase_10kHz.ino
diff --git a/examples/ESP32_S2_3phase_10kHz/ESP32_S2_3phase_10kHz.ino b/examples/Pwm_ESP32_S2_3phase_10kHz/Pwm_ESP32_S2_3phase_10kHz.ino
similarity index 100%
rename from examples/ESP32_S2_3phase_10kHz/ESP32_S2_3phase_10kHz.ino
rename to examples/Pwm_ESP32_S2_3phase_10kHz/Pwm_ESP32_S2_3phase_10kHz.ino
diff --git a/examples/Fade/Fade.ino b/examples/Pwm_Fade/Pwm_Fade.ino
similarity index 100%
rename from examples/Fade/Fade.ino
rename to examples/Pwm_Fade/Pwm_Fade.ino
diff --git a/examples/ESP32_Fade16/ESP32_Fade16.ino b/examples/Pwm_Fade16/Pwm_Fade16.ino
similarity index 100%
rename from examples/ESP32_Fade16/ESP32_Fade16.ino
rename to examples/Pwm_Fade16/Pwm_Fade16.ino
diff --git a/examples/ESP32_Fade_Servo/ESP32_Fade_Servo.ino b/examples/Pwm_Fade_Servo/Pwm_Fade_Servo.ino
similarity index 100%
rename from examples/ESP32_Fade_Servo/ESP32_Fade_Servo.ino
rename to examples/Pwm_Fade_Servo/Pwm_Fade_Servo.ino
diff --git a/examples/ESP32_Sync2_300kHz/ESP32_Sync2_300kHz.ino b/examples/Pwm_Sync2_300kHz/Pwm_Sync2_300kHz.ino
similarity index 100%
rename from examples/ESP32_Sync2_300kHz/ESP32_Sync2_300kHz.ino
rename to examples/Pwm_Sync2_300kHz/Pwm_Sync2_300kHz.ino
diff --git a/examples/ESP32_C3_Interrupt_Servo_Ease_Speed/ESP32_C3_Interrupt_Servo_Ease_Speed.ino b/examples/Servo_Easing_Interrupt/Servo_Easing_Interrupt.ino
similarity index 92%
rename from examples/ESP32_C3_Interrupt_Servo_Ease_Speed/ESP32_C3_Interrupt_Servo_Ease_Speed.ino
rename to examples/Servo_Easing_Interrupt/Servo_Easing_Interrupt.ino
index 5dfb4a1..ec93ba3 100644
--- a/examples/ESP32_C3_Interrupt_Servo_Ease_Speed/ESP32_C3_Interrupt_Servo_Ease_Speed.ino
+++ b/examples/Servo_Easing_Interrupt/Servo_Easing_Interrupt.ino
@@ -35,7 +35,7 @@
The delay of 50 ms was added to control the plotter sample period.
*/
-#include
+#include
const int servoPin = 8;
volatile float ke = 0.0; // easing curve
@@ -44,10 +44,11 @@ volatile float pos = 90; // servo position (degrees)
volatile float ye; // calculated servo position (normalized)
hw_timer_t *Timer0 = NULL;
-Pwm pwm = Pwm();
+
+Servo myservo = Servo();
void IRAM_ATTR Timer0_ISR() {
- ye = pwm.writeServo(servoPin, pos, speed, ke);
+ ye = myservo.write(servoPin, pos, speed, ke);
}
void setup() {
@@ -56,20 +57,20 @@ void setup() {
Timer0 = timerBegin(0, 80, true);
timerAttachInterrupt(Timer0, &Timer0_ISR, true);
timerAlarmWrite(Timer0, 20000, true); // 20 ms
- pwm.writeServo(servoPin, pos, speed, ke); // attach servo
+ myservo.write(servoPin, pos, speed, ke); // attach servo
timerAlarmEnable(Timer0);
// slowly go to 0 degrees, linear easing
pos = 0.0;
speed = 30;
ke = 0.0;
- ye = pwm.writeServo(servoPin, pos, speed, ke);
+ ye = myservo.write(servoPin, pos, speed, ke);
while (ye > 0);
// setup faster speed and new easing curve
speed = 100;
ke = 0.7;
- ye = pwm.writeServo(servoPin, pos, speed, ke);
+ ye = myservo.write(servoPin, pos, speed, ke);
}
void loop() {
diff --git a/examples/Servo_Easing_Time/Servo_Easing_Time.ino b/examples/Servo_Easing_Time/Servo_Easing_Time.ino
deleted file mode 100644
index 1745257..0000000
--- a/examples/Servo_Easing_Time/Servo_Easing_Time.ino
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- Controls three servos with different easing settings
- New position command after elapsed time based position change and speed.
- https://wokwi.com/projects/360276061783595009
- by dlloydev, March 2023.
-
- ⚪ The green servo moves from 0 to 90 deg at 70 deg/s with linear motion.
- ⚪ The orange servo moves from 0 to 180 deg at 140 deg/s with sigmoid motion.
- ⚪ The purple servo moves from 45 to 135 deg at 180 deg/s with steep sigmoid motion.
-*/
-
-#include
-
-const int servoPin1 = 18;
-const int servoPin2 = 19;
-const int servoPin3 = 21;
-
-// units in degrees per second
-float speed1 = 70.0;
-float speed2 = 140.0;
-float speed3 = 180.0;
-
-// When easing constant (ke) < 1.0, return value is normalized, when 1.0, returns pulse width (μs)
-// ke = 0.0 is linear, between 0.0 and 1.0 is tunable sigmoid, 1.0 is normal response
-// Normalized Tunable Sigmoid: https://www.desmos.com/calculator/ejkcwglzd1
-float ke1 = 0.0;
-float ke2 = 0.6;
-float ke3 = 0.8;
-
-// go to position (degrees)
-uint8_t pos1 = 90;
-uint8_t pos2 = 180;
-uint8_t pos3 = 135;
-
-// duration of travel in ms is degrees to move / speed * 1000
-float dur1 = 90.0 / speed1 * 1000.0;
-float dur2 = 180.0 / speed2 * 1000.0;
-float dur3 = 90.0 / speed3 * 1000.0;
-
-uint32_t prevMs1, prevMs2, prevMs3;
-
-Pwm pwm = Pwm();
-
-void setup() {
- Serial.begin(115200);
-}
-
-void loop() {
- uint32_t ms1 = millis();
- uint32_t ms2 = ms1;
- uint32_t ms3 = ms1;
- float ye1, ye2, ye3;
-
- if (ms1 - prevMs1 > dur1) {
- prevMs1 = ms1;
- pos1 = (pos1 == 0) ? 90 : 0;
- }
- if (ms2 - prevMs2 > dur2) {
- prevMs2 = ms2;
- pos2 = (pos2 == 0) ? 180 : 0;
- }
- if (ms3 - prevMs3 > dur3) {
- prevMs3 = ms3;
- pos3 = (pos3 == 45) ? 135 : 45;
- }
- ye1 = pwm.writeServo(servoPin1, pos1, speed1, ke1);
- ye2 = pwm.writeServo(servoPin2, pos2, speed2, ke2);
- ye3 = pwm.writeServo(servoPin3, pos3, speed3, ke3);
- Serial.print(ye1);
- Serial.print(",");
- Serial.print(ye2);
- Serial.print(",");
- Serial.println(ye3);
- delay(6);
-}
diff --git a/examples/ESP32_C3_6_Servo_Knob/ESP32_C3_6_Servo_Knob.ino b/examples/Servo_Knob_Six/Servo_Knob_Six.ino
similarity index 72%
rename from examples/ESP32_C3_6_Servo_Knob/ESP32_C3_6_Servo_Knob.ino
rename to examples/Servo_Knob_Six/Servo_Knob_Six.ino
index 56d323e..65c68e1 100644
--- a/examples/ESP32_C3_6_Servo_Knob/ESP32_C3_6_Servo_Knob.ino
+++ b/examples/Servo_Knob_Six/Servo_Knob_Six.ino
@@ -4,9 +4,9 @@
by dlloydev, February 2023.
*/
-#include
+#include
-Pwm pwm = Pwm();
+Servo myservo = Servo();
const int potPin1 = 0, servoPin1 = 6;
const int potPin2 = 1, servoPin2 = 7;
@@ -22,27 +22,27 @@ void loop() {
int val1 = analogRead(potPin1); // read the pot value (0-4095)
val1 = map(val1, 700, 3395, 0, 180); // align pot pointer to servo arm
- pwm.writeServo(servoPin1, val1); // set the servo position (degrees)
+ myservo.write(servoPin1, val1); // set the servo position (degrees)
int val2 = analogRead(potPin2); // read the pot value (0-4095)
val2 = map(val2, 700, 3395, 0, 180); // align pot pointer to servo arm
- pwm.writeServo(servoPin2, val2); // set the servo position (degrees)
+ myservo.write(servoPin2, val2); // set the servo position (degrees)
int val3 = analogRead(potPin3); // read the pot value (0-4095)
val3 = map(val3, 700, 3395, 0, 180); // align pot pointer to servo arm
- pwm.writeServo(servoPin3, val3); // set the servo position (degrees)
+ myservo.write(servoPin3, val3); // set the servo position (degrees)
int val4 = analogRead(potPin4); // read the pot value (0-4095)
val4 = map(val4, 700, 3395, 0, 180); // align pot pointer to servo arm
- pwm.writeServo(servoPin4, val4); // set the servo position (degrees)
+ myservo.write(servoPin4, val4); // set the servo position (degrees)
int val5 = analogRead(potPin5); // read the pot value (0-4095)
val5 = map(val5, 700, 3395, 0, 180); // align pot pointer to servo arm
- pwm.writeServo(servoPin5, val5); // set the servo position (degrees)
+ myservo.write(servoPin5, val5); // set the servo position (degrees)
int val6 = analogRead(potPin6); // read the pot value (0-4095)
val6 = map(val6, 700, 3395, 0, 180); // align pot pointer to servo arm
- pwm.writeServo(servoPin6, val6); // set the servo position (degrees)
+ myservo.write(servoPin6, val6); // set the servo position (degrees)
delay(10);
}
diff --git a/examples/Servo_Sweep_Inverted/Servo_Sweep_Inverted.ino b/examples/Servo_Sweep_Inverted/Servo_Sweep_Inverted.ino
index ee1557b..bc4fe48 100644
--- a/examples/Servo_Sweep_Inverted/Servo_Sweep_Inverted.ino
+++ b/examples/Servo_Sweep_Inverted/Servo_Sweep_Inverted.ino
@@ -5,27 +5,31 @@
This demonstrates using an inverted PWM output for servo control.
It allows using only one transistor to drive a higher voltage Servo control signal.
- No additional latency is added like found with software inversion, because the inverted
- pulse remains at the start of the refresh period rather than being flipped to the end.
+ No additional latency added as the signal is inverted by the timer peripheral.
+ Choose/edit an attach function parameter to customize the signal configuration.
*/
-#include
+#include
-Pwm pwm = Pwm();
+Servo myservo = Servo();
const int servoPin = 5, ch = 0;
void setup() {
-pwm.attach(servoPin, ch, 544, 2400, 0, 1, true);
+ Serial.begin(115200);
+ myservo.attach(servoPin, true); // attach to first free channel, inverted pwm
+ //myservo.attach(servoPin, 3, true); // attach to channel 3, inverted pwm
+ //myservo.attach(servoPin, 6, 500, 2500, true); // attach to ch 6, minUs=500 maxUs=2500, inverted pwm
+ myservo.printDebug();
}
void loop() {
- for (int pos = 0; pos <= 180; pos++) { // go from 0-180 degrees
- pwm.writeServo(servoPin, pos); // set the servo position (degrees)
+ for (int pos = 0; pos <= 180; pos++) {
+ myservo.write(servoPin, pos);
delay(15);
}
- for (int pos = 180; pos >= 0; pos--) { // go from 180-0 degrees
- pwm.writeServo(servoPin, pos); // set the servo position (degrees)
+ for (int pos = 180; pos >= 0; pos--) {
+ myservo.write(servoPin, pos);
delay(15);
}
-}
\ No newline at end of file
+}
diff --git a/examples/Dual_Servo_Sweep_Speed/Dual_Servo_Sweep_Speed.ino b/examples/Servo_Sweep_Speed/Servo_Sweep_Speed.ino
similarity index 90%
rename from examples/Dual_Servo_Sweep_Speed/Dual_Servo_Sweep_Speed.ino
rename to examples/Servo_Sweep_Speed/Servo_Sweep_Speed.ino
index da5a902..540b5f1 100644
--- a/examples/Dual_Servo_Sweep_Speed/Dual_Servo_Sweep_Speed.ino
+++ b/examples/Servo_Sweep_Speed/Servo_Sweep_Speed.ino
@@ -4,9 +4,9 @@
by dlloydev, December 2022.
*/
-#include
+#include
-Pwm pwm = Pwm();
+Servo myservo = Servo();
const int speedPin1 = 32, speedPin2 = 12;
const int servoPin1 = 14, servoPin2 = 13;
@@ -20,9 +20,9 @@ void loop() {
speed1 = (analogRead(speedPin1)) / 4095.0; // 0-100% speed
speed2 = (analogRead(speedPin2)) / 2047.0; // 0-200% speed
- pwm.writeServo(servoPin1, pos1);
+ myservo.write(servoPin1, pos1);
delay(5); // for simulator
- pwm.writeServo(servoPin2, pos2);
+ myservo.write(servoPin2, pos2);
delay(5); // for simulator
if (pos1 < 0) pos1 = 0;
diff --git a/examples/playingTones/playingTones.ino b/examples/Tone_Player/Tone_Player.ino
similarity index 100%
rename from examples/playingTones/playingTones.ino
rename to examples/Tone_Player/Tone_Player.ino
diff --git a/keywords.txt b/keywords.txt
index 99739fd..a2f781e 100644
--- a/keywords.txt
+++ b/keywords.txt
@@ -4,7 +4,9 @@
Pwm KEYWORD1
pwm KEYWORD1
-pinStatus_t KEYWORD1
+Servo KEYWORD1
+myservo KEYWORD1
+mem_t KEYWORD1
#######################################
# Methods and Functions
@@ -12,19 +14,27 @@ pinStatus_t KEYWORD1
write KEYWORD2
writeServo KEYWORD2
+writePwm KEYWORD2
+writeMicroseconds KEYWORD2
read KEYWORD2
+readMicroseconds KEYWORD2
tone KEYWORD2
note KEYWORD2
readMicroseconds KEYWORD2
attach KEYWORD2
+attachInvert KEYWORD2
+attachServo KEYWORD2
+attachPwm KEYWORD2
attached KEYWORD2
attachedPin KEYWORD2
+firstFreeCh KEYWORD2
detach KEYWORD2
+detached KEYWORD2
pause KEYWORD2
resume KEYWORD2
setFrequency KEYWORD2
setResolution KEYWORD2
-printConfig KEYWORD2
+printDebug KEYWORD2
#######################################
# Constants
diff --git a/library.json b/library.json
index 05a9aa7..6be4383 100644
--- a/library.json
+++ b/library.json
@@ -3,7 +3,7 @@
"keywords": "pwm, servo, tone, esp32, analogWrite, esp32-s2, esp32-s3, esp32-c3, ledc",
"description": "ESP32 PWM, Servo, Easing and Tone. Smart GPIO pin management and advanced control features.",
"license": "MIT",
- "version": "4.3.4",
+ "version": "5.0.0",
"frameworks": "arduino",
"platforms": "espressif32",
"repository": {
diff --git a/library.properties b/library.properties
index c74d236..624d84c 100644
--- a/library.properties
+++ b/library.properties
@@ -1,5 +1,5 @@
name=ESP32 ESP32S2 AnalogWrite
-version=4.3.4
+version=5.0.0
author=David Lloyd
maintainer=David Lloyd
sentence=ESP32 PWM, Servo, Easing and Tone.
diff --git a/src/Servo.h b/src/Servo.h
new file mode 100644
index 0000000..f541a64
--- /dev/null
+++ b/src/Servo.h
@@ -0,0 +1,171 @@
+#pragma once
+#ifndef Servo_h
+#define Servo_h
+
+#include
+#include "pwmWrite.h"
+
+class Servo
+{
+
+ Pwm pwm;
+
+ private:
+
+ public:
+
+ // servo
+
+ uint8_t attach(uint8_t pin) {
+ return pwm.attachServo(pin);
+ };
+
+ uint8_t attach(uint8_t pin, bool invert) {
+ return pwm.attachServo(pin, invert);
+ };
+
+ uint8_t attach(uint8_t pin, uint8_t ch) {
+ return pwm.attachServo(pin, ch);
+ };
+
+ uint8_t attach(uint8_t pin, uint8_t ch, bool invert) {
+ return pwm.attachServo(pin, ch, invert);
+ };
+
+ uint8_t attach(uint8_t pin, uint16_t minUs, uint16_t maxUs) {
+ return pwm.attachServo(pin, minUs, maxUs);
+ };
+
+ uint8_t attach(uint8_t pin, uint8_t ch, uint16_t minUs, uint16_t maxUs) {
+ return pwm.attachServo(pin, ch, minUs, maxUs);
+ };
+
+ uint8_t attach(uint8_t pin, uint8_t ch, uint16_t minUs, uint16_t maxUs, bool invert) {
+ return pwm.attachServo(pin, ch, minUs, maxUs, invert);
+ };
+
+ uint8_t attach(uint8_t pin, uint16_t minUs, uint16_t maxUs, float speed, float ke) {
+ return pwm.attachServo(pin, minUs, maxUs, speed, ke);
+ };
+
+ uint8_t attach(uint8_t pin, uint8_t ch, uint16_t minUs, uint16_t maxUs, float speed, float ke) {
+ return pwm.attachServo(pin, ch, minUs, maxUs, speed, ke);
+ };
+
+ uint8_t attach(uint8_t pin, uint8_t ch, uint16_t minUs, uint16_t maxUs, float speed, float ke, bool invert) {
+ return pwm.attachServo(pin, ch, minUs, maxUs, speed, ke, invert);
+ };
+
+ float read(uint8_t pin) {
+ return pwm.read(pin);
+ };
+
+ float readMicroseconds(uint8_t pin) {
+ return pwm.readMicroseconds(pin);
+ };
+
+ float write(uint8_t pin, float value) {
+ return pwm.writeServo(pin, value);
+ };
+
+ float writeMicroseconds(uint8_t pin, float value) {
+ return pwm.writeServo(pin, value);
+ };
+
+ float write(uint8_t pin, float value, float speed, float ke) {
+ return pwm.writeServo(pin, value, speed, ke);
+ };
+
+ float writeMicroseconds(uint8_t pin, float value, float speed, float ke) {
+ return pwm.writeServo(pin, value, speed, ke);
+ };
+
+ // common
+
+ uint8_t attached(uint8_t pin) { // check if pin is attached
+ return pwm.attached(pin);
+ };
+
+ uint8_t attachedPin(uint8_t ch) { // get pin on specified channel
+ return pwm.attachedPin(ch);
+ };
+
+ uint8_t firstFreeCh(void) { // get first free channel
+ return pwm.firstFreeCh();
+ };
+
+ void detach(uint8_t pin) { // detach pin
+ pwm.detach(pin);
+ };
+
+ bool detached(uint8_t pin) { // check if pin is detached
+ return pwm.detached(pin);
+ };
+
+ void pause(uint8_t ch = 255) { // pause timer on all or specified channel
+ pwm.pause(ch);
+ };
+
+ void resume(uint8_t ch = 255) { // resume timer on all or specified channel
+ pwm.resume(ch);
+ };
+
+ void printDebug(void) { // print the status of all channels
+ pwm.printDebug();
+ };
+
+ float setFrequency(uint8_t pin, uint32_t frequency = 1000) {
+ return pwm.setFrequency(pin, frequency);
+ };
+
+ uint8_t setResolution(uint8_t pin, uint8_t resolution = 10) {
+ return pwm.setResolution(pin, resolution);
+ };
+
+ // pwm
+
+ float writePwm(uint8_t pin, uint32_t duty) {
+ return pwm.write(pin, duty);
+ };
+
+ float writePwm(uint8_t pin, uint32_t duty, uint32_t frequency) {
+ return pwm.write(pin, duty, frequency);
+ };
+
+ float writePwm(uint8_t pin, uint32_t duty, uint32_t frequency, uint8_t resolution) {
+ return pwm.write(pin, duty, frequency, resolution);
+ };
+
+ float writePwm(uint8_t pin, uint32_t duty, uint32_t frequency, uint8_t resolution, uint32_t phase) {
+ return pwm.write(pin, duty, frequency, resolution, phase);
+ };
+
+ uint8_t attachPwm(uint8_t pin) { // attach pin to next free channel
+ return pwm.attach(pin);
+ };
+
+ uint8_t attachPwm(uint8_t pin, uint8_t ch) { // attach to specified channel
+ return pwm.attach(pin, ch);
+ };
+
+ uint8_t attachInvert(uint8_t pin) { // attach pin to next free channel with inverted pwm
+ return pwm.attachInvert(pin);
+ };
+
+ uint8_t attachInvert(uint8_t pin, uint8_t ch) { // attach to specified ch with inverted pwm
+ return pwm.attachInvert(pin, ch);
+ };
+
+ // tone and note
+
+ void tone(uint8_t pin, uint32_t frequency, uint16_t duration = 500, uint16_t interval = 0) {
+ pwm.tone(pin, frequency, duration, interval);
+ };
+
+ void note(uint8_t pin, note_t note, uint8_t octave, uint16_t duration, uint16_t interval) {
+ pwm.note(pin, note, octave, duration, interval);
+ };
+
+};
+
+#endif
diff --git a/src/pwmWrite.cpp b/src/pwmWrite.cpp
index 9992856..91acfe2 100644
--- a/src/pwmWrite.cpp
+++ b/src/pwmWrite.cpp
@@ -1,8 +1,8 @@
-/*******************************************************************
- ESP32 PWM, SERVO and TONE Library, Version 4.3.4
+/*
+ ESP32 PWM, SERVO and TONE Library, Version 5.0.0
by dlloydev https://github.com/Dlloydev/ESP32-ESP32S2-AnalogWrite
- This Library is licensed under the MIT License
- *******************************************************************/
+ License: MIT
+*/
#include
#include "pwmWrite.h"
@@ -124,19 +124,11 @@ float Pwm::readMicroseconds(uint8_t pin) {
}
uint8_t Pwm::attach(uint8_t pin) {
- uint8_t ch = attached(pin);
- if (ch == 253) { // free channels exist
- for (uint8_t c = 0; c < chMax; c++) {
- if (mem[c].pin == 255 && ch == 253) { //first free ch
- mem[c].pin = pin;
- ch = c;
- ledcSetup(ch, mem[ch].frequency, mem[ch].resolution);
- if (sync) pause(ch);
- ledcAttachPin(pin, ch);
- return ch;
- }
- }
- }
+ uint8_t ch = firstFreeCh();
+ if (ch < chMax) mem[ch].pin = pin;
+ ledcSetup(ch, mem[ch].frequency, mem[ch].resolution);
+ if (sync) pause(ch);
+ ledcAttachPin(pin, ch);
return ch;
}
@@ -151,19 +143,11 @@ uint8_t Pwm::attach(uint8_t pin, uint8_t ch) {
}
uint8_t Pwm::attachInvert(uint8_t pin) {
- uint8_t ch = attached(pin);
- if (ch == 253) { // free channels exist
- for (uint8_t c = 0; c < chMax; c++) {
- if (mem[c].pin == 255 && ch == 253) { //first free ch
- mem[c].pin = pin;
- ch = c;
- ledcSetup(ch, mem[ch].frequency, mem[ch].resolution);
- if (sync) pause(ch);
- ledc_attach_with_invert(pin, ch);
- return ch;
- }
- }
- }
+ uint8_t ch = firstFreeCh();
+ if (ch < chMax) mem[ch].pin = pin;
+ ledcSetup(ch, mem[ch].frequency, mem[ch].resolution);
+ if (sync) pause(ch);
+ ledc_attach_with_invert(pin, ch);
return ch;
}
@@ -177,31 +161,60 @@ uint8_t Pwm::attachInvert(uint8_t pin, uint8_t ch) {
return ch;
}
-uint8_t Pwm::attach(uint8_t pin, uint16_t minUs, uint16_t maxUs) {
+uint8_t Pwm::attachServo(uint8_t pin) {
+ uint8_t ch = firstFreeCh();
+ if (ch < chMax) config_servo(ch, mem[ch].servoMinUs, mem[ch].servoMaxUs);
+ return attach(pin, ch);
+}
+
+uint8_t Pwm::attachServo(uint8_t pin, bool invert) {
+ uint8_t ch = firstFreeCh();
+ if (ch < chMax) config_servo(ch, mem[ch].servoMinUs, mem[ch].servoMaxUs);
+ return (invert) ? attachInvert(pin, ch) : attach(pin, ch);
+}
+
+uint8_t Pwm::attachServo(uint8_t pin, uint8_t ch) {
+ if (ch < chMax) config_servo(ch, mem[ch].servoMinUs, mem[ch].servoMaxUs);
+ return attach(pin, ch);
+}
+
+uint8_t Pwm::attachServo(uint8_t pin, uint8_t ch, bool invert) {
+ if (ch < chMax) config_servo(ch, mem[ch].servoMinUs, mem[ch].servoMaxUs);
+ uint8_t chan = (invert) ? attachInvert(pin, ch) : attach(pin, ch);
+ return chan;
+}
+
+uint8_t Pwm::attachServo(uint8_t pin, uint16_t minUs, uint16_t maxUs) {
uint8_t ch = attach(pin);
if (ch < chMax) config_servo(ch, minUs, maxUs);
return ch;
}
-uint8_t Pwm::attach(uint8_t pin, uint8_t ch, uint16_t minUs, uint16_t maxUs) {
+uint8_t Pwm::attachServo(uint8_t pin, uint8_t ch, uint16_t minUs, uint16_t maxUs) {
config_servo(ch, minUs, maxUs);
return attach(pin, ch);
}
-uint8_t Pwm::attach(uint8_t pin, uint16_t minUs, uint16_t maxUs, float speed, float ke) {
+uint8_t Pwm::attachServo(uint8_t pin, uint8_t ch, uint16_t minUs, uint16_t maxUs, bool invert) {
+ config_servo(ch, minUs, maxUs);
+ uint8_t chan = (invert) ? attachInvert(pin, ch) : attach(pin, ch);
+ return chan;
+}
+
+uint8_t Pwm::attachServo(uint8_t pin, uint16_t minUs, uint16_t maxUs, float speed, float ke) {
uint8_t ch = attach(pin);
if (ch < chMax) config_servo(ch, minUs, maxUs, speed, ke);
return ch;
}
-uint8_t Pwm::attach(uint8_t pin, uint8_t ch, uint16_t minUs, uint16_t maxUs, float speed, float ke) {
+uint8_t Pwm::attachServo(uint8_t pin, uint8_t ch, uint16_t minUs, uint16_t maxUs, float speed, float ke) {
config_servo(ch, minUs, maxUs, speed, ke);
return attach(pin, ch);
}
-uint8_t Pwm::attach(uint8_t pin, uint8_t ch, uint16_t minUs, uint16_t maxUs, float speed, float ke, bool invert) {
+uint8_t Pwm::attachServo(uint8_t pin, uint8_t ch, uint16_t minUs, uint16_t maxUs, float speed, float ke, bool invert) {
config_servo(ch, minUs, maxUs, speed, ke);
- uint8_t chan = attachInvert(pin, ch);
+ uint8_t chan = (invert) ? attachInvert(pin, ch) : attach(pin, ch);
return chan;
}
@@ -219,6 +232,13 @@ uint8_t Pwm::attachedPin(uint8_t ch) {
return mem[ch].pin;
}
+uint8_t Pwm::firstFreeCh(void) {
+ for (uint8_t ch = 0; ch < chMax; ch++) {
+ if (mem[ch].pin == 255) return ch;
+ }
+ return 255;
+}
+
void Pwm::detach(uint8_t pin) {
uint8_t ch = attached(pin);
if (ch < chMax) {
@@ -292,7 +312,7 @@ void Pwm::printDebug() {
Serial.printf("\n");
}
-/************************* private functions ***************************/
+/***** private functions *****/
void Pwm::ledc_attach_with_invert(uint8_t pin, uint8_t ch) {
if (ch >= chMax) return;
diff --git a/src/pwmWrite.h b/src/pwmWrite.h
index 96b630f..a265ad1 100644
--- a/src/pwmWrite.h
+++ b/src/pwmWrite.h
@@ -77,19 +77,22 @@ class Pwm {
float write(uint8_t pin, uint32_t duty, uint32_t frequency);
float write(uint8_t pin, uint32_t duty, uint32_t frequency, uint8_t resolution);
float write(uint8_t pin, uint32_t duty, uint32_t frequency, uint8_t resolution, uint32_t phase);
-
- // pwm
- uint8_t attach(uint8_t pin); // attach pin to next free channel
- uint8_t attach(uint8_t pin, uint8_t ch); // attach to specified ch
- uint8_t attachInvert(uint8_t pin); // attach pin to next free channel with inverted pwm
- uint8_t attachInvert(uint8_t pin, uint8_t ch); // attach to specified ch with inverted pwm
+ uint8_t attach(uint8_t pin); // attach pin to next free channel
+ uint8_t attach(uint8_t pin, uint8_t ch); // attach to specified ch
+ uint8_t attachInvert(uint8_t pin); // attach pin to next free channel with inverted pwm
+ uint8_t attachInvert(uint8_t pin, uint8_t ch); // attach to specified ch with inverted pwm
// servo
- uint8_t attach(uint8_t pin, uint16_t minUs, uint16_t maxUs);
- uint8_t attach(uint8_t pin, uint8_t ch, uint16_t minUs, uint16_t maxUs);
- uint8_t attach(uint8_t pin, uint16_t minUs, uint16_t maxUs, float speed, float ke);
- uint8_t attach(uint8_t pin, uint8_t ch, uint16_t minUs, uint16_t maxUs, float speed, float ke);
- uint8_t attach(uint8_t pin, uint8_t ch, uint16_t minUs, uint16_t maxUs, float speed, float ke, bool invert);
+ uint8_t attachServo(uint8_t pin);
+ uint8_t attachServo(uint8_t pin, bool invert);
+ uint8_t attachServo(uint8_t pin, uint8_t ch);
+ uint8_t attachServo(uint8_t pin, uint8_t ch, bool invert);
+ uint8_t attachServo(uint8_t pin, uint16_t minUs, uint16_t maxUs);
+ uint8_t attachServo(uint8_t pin, uint8_t ch, uint16_t minUs, uint16_t maxUs);
+ uint8_t attachServo(uint8_t pin, uint8_t ch, uint16_t minUs, uint16_t maxUs, bool invert);
+ uint8_t attachServo(uint8_t pin, uint16_t minUs, uint16_t maxUs, float speed, float ke);
+ uint8_t attachServo(uint8_t pin, uint8_t ch, uint16_t minUs, uint16_t maxUs, float speed, float ke);
+ uint8_t attachServo(uint8_t pin, uint8_t ch, uint16_t minUs, uint16_t maxUs, float speed, float ke, bool invert);
float read(uint8_t pin);
float readMicroseconds(uint8_t pin);
float writeServo(uint8_t pin, float value);
@@ -100,8 +103,9 @@ class Pwm {
void note(uint8_t pin, note_t note, uint8_t octave, uint16_t duration, uint16_t interval);
// common
- uint8_t attached(uint8_t pin); // check if pin is attaced
+ uint8_t attached(uint8_t pin); // check if pin is attached
uint8_t attachedPin(uint8_t ch); // get pin on specified channel
+ uint8_t firstFreeCh(void); // get first free channel
void detach(uint8_t pin); // detach pin
bool detached(uint8_t pin); // check if pin is detached
void pause(uint8_t ch = 255); // pause timer on all or specified channel
@@ -122,4 +126,5 @@ class Pwm {
void reset_fields(uint8_t ch);
bool sync = false;
};
+
#endif