Skip to content

Commit

Permalink
Improve the documentation of the library and especially function atta…
Browse files Browse the repository at this point in the history
…ch() #1
  • Loading branch information
JarekParal committed Mar 1, 2019
1 parent 2dec948 commit 4bb66d8
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vscode
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ env:
- PLATFORMIO_CI_SRC=examples/01-SimpleServo
- PLATFORMIO_CI_SRC=examples/02-ServoPotentiometer
- PLATFORMIO_CI_SRC=examples/03-MultipleServos
- PLATFORMIO_CI_SRC=examples/04-SimpleServoAngles

install:
- pip install -U platformio
Expand Down
28 changes: 25 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,30 @@
# ESP32-Arduino-Servo-Library
# ESP32-Arduino-Servo-Library [![Build Status](https://travis-ci.org/RoboticsBrno/ESP32-Arduino-Servo-Library.svg?branch=master)](https://travis-ci.org/RoboticsBrno/ESP32-Arduino-Servo-Library)

Generate RC servo signal on a selected pin.

Base on [servo library for stm32f4 (d2a4a47)](https://github.com/arduino-libraries/Servo/blob/master/src/stm32f4/ServoTimers.h).

The same interface as Arduino/Servo: https://www.arduino.cc/en/Reference/Servo
## Interface

The interface is similar to Arduino/Servo: https://www.arduino.cc/en/Reference/Servo

But the function `atach()` is different:

```c
bool attach(
int pin,
int channel = CHANNEL_NOT_ATTACHED,
int minAngle = MIN_ANGLE,
int maxAngle = MAX_ANGLE,
int minPulseWidth = MIN_PULSE_WIDTH,
int maxPulseWidth = MAX_PULSE_WIDTH
);
```

More information in [source code documentation](https://github.com/RoboticsBrno/ESP32-Arduino-Servo-Library/blob/master/src/Servo.h#L73).

Example: [04-SimpleServoAngles](examples/04-SimpleServoAngles/04-SimpleServoAngles.ino)

## PlatformIO

Also available through the PlatformIO: http://platformio.org/lib/show/1739/ServoESP32
This library is also available at the [PlatformIO](https://platformio.org) as [ServoESP32](http://platformio.org/lib/show/1739/ServoESP32).
34 changes: 34 additions & 0 deletions examples/04-SimpleServoAngles/04-SimpleServoAngles.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <Servo.h>

/*
* Description:
* Example for setting the minimal and maximal angle.
*/

static const int servoPin = 4;

Servo servo1;

void setup() {
Serial.begin(115200);
servo1.attach(
servoPin,
Servo::CHANNEL_NOT_ATTACHED,
45,
120
);
}

void loop() {
for(int posDegrees = 0; posDegrees <= 180; posDegrees++) {
servo1.write(posDegrees);
Serial.println(posDegrees);
delay(20);
}

for(int posDegrees = 180; posDegrees >= 0; posDegrees--) {
servo1.write(posDegrees);
Serial.println(posDegrees);
delay(20);
}
}
21 changes: 13 additions & 8 deletions src/Servo.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,19 @@ class Servo {
* @param pin Pin connected to the servo pulse wave input. This
* pin must be capable of PWM output (all ESP32 pins).
*
* @param channel Channel which is set to ESP32 Arduino function ledcSetup().
* Channel must be number between 0 - 15.
* It is possible to use automatic channel setup with constant
* Servo::CHANNEL_NOT_ATTACHED.
*
* @param minAngle Target angle (in degrees) associated with
* minPulseWidth. Defaults to
* MIN_ANGLE = 0.
*
* @param maxAngle Target angle (in degrees) associated with
* maxPulseWidth. Defaults to
* MAX_ANGLE = 180.
*
* @param minPulseWidth Minimum pulse width to write to pin, in
* microseconds. This will be associated
* with a minAngle degree angle. Defaults to
Expand All @@ -87,14 +100,6 @@ class Servo {
* with a maxAngle degree angle. Defaults to
* MAX_PULSE_WIDTH = 2400.
*
* @param minAngle Target angle (in degrees) associated with
* minPulseWidth. Defaults to
* MIN_ANGLE = 0.
*
* @param maxAngle Target angle (in degrees) associated with
* maxPulseWidth. Defaults to
* MAX_ANGLE = 180.
*
* @sideeffect May set pinMode(pin, PWM).
*
* @return true if successful, false when pin doesn't support PWM.
Expand Down

0 comments on commit 4bb66d8

Please sign in to comment.