Skip to content

Commit 4c4906f

Browse files
committed
Overload attach: can specify initial angle for servo, too.
1 parent e7695a9 commit 4c4906f

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

libraries/Servo/src/Servo.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ uint8_t Servo::attach(int pin)
6262
}
6363

6464
uint8_t Servo::attach(int pin, uint16_t minUs, uint16_t maxUs)
65+
{
66+
return attach(pin, minUs, maxUs, _valueUs);
67+
}
68+
69+
uint8_t Servo::attach(int pin, uint16_t minUs, uint16_t maxUs, int value)
6570
{
6671
if (!_attached) {
6772
digitalWrite(pin, LOW);
@@ -76,7 +81,7 @@ uint8_t Servo::attach(int pin, uint16_t minUs, uint16_t maxUs)
7681
_maxUs = max((uint16_t)250, min((uint16_t)3000, maxUs));
7782
_minUs = max((uint16_t)200, min(_maxUs, minUs));
7883

79-
write(_valueUs);
84+
write(value);
8085

8186
return pin;
8287
}

libraries/Servo/src/Servo.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,15 @@ class Servo
6363
public:
6464
Servo();
6565
~Servo();
66-
uint8_t attach(int pin); // attach the given pin to the next free channel, sets pinMode, returns channel number or 0 if failure
67-
uint8_t attach(int pin, uint16_t min, uint16_t max); // as above but also sets min and max values for writes.
66+
// attach the given pin to the next free channel, sets pinMode, returns channel number or 0 if failure.
67+
uint8_t attach(int pin);
68+
// attach the given pin to the next free channel, sets pinMode, min, and max values for writes.
69+
// returns channel number or 0 if failure.
70+
uint8_t attach(int pin, uint16_t min, uint16_t max);
71+
// attach the given pin to the next free channel, sets pinMode, min, max values for writes,
72+
// and sets the initial value, the same as write.
73+
// returns channel number or 0 if failure.
74+
uint8_t attach(int pin, uint16_t min, uint16_t max, int value);
6875
void detach();
6976
void write(int value); // if value is < 200 its treated as an angle, otherwise as pulse width in microseconds
7077
void writeMicroseconds(int value); // Write pulse width in microseconds

0 commit comments

Comments
 (0)