Skip to content

Commit f67f03b

Browse files
jan019fpistm
authored andcommitted
Fix issue with writing inital servo value before min/max is configured
The call to function Servo::write() in Servo::attach() must be done after Servo::min and Servo::max are configured - Servo::write() uses the min/max for mapping the passed value if the value is passed in degrees. Therefore if inital value in attach is set in degress and min/max is not configured when call to Servo::write() is done, the mapping will not be correct. Resolves: #2308
1 parent 8f337e8 commit f67f03b

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

Diff for: libraries/Servo/src/stm32/Servo.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,12 @@ uint8_t Servo::attach(int pin, int min, int max, int value)
121121
if (this->servoIndex < MAX_SERVOS) {
122122
pinMode(pin, OUTPUT); // set servo pin to output
123123
servos[this->servoIndex].Pin.nbr = pin;
124-
write(value);
125124
// todo min/max check: abs(min - MIN_PULSE_WIDTH) /4 < 128
126125
this->min = (MIN_PULSE_WIDTH - min) / 4; //resolution of min/max is 4 uS
127126
this->max = (MAX_PULSE_WIDTH - max) / 4;
127+
128+
write(value); // set the initial position
129+
128130
// initialize the timer if it has not already been initialized
129131
if (isTimerActive() == false) {
130132
TimerServoInit();

0 commit comments

Comments
 (0)