Skip to content

Commit 85a1f01

Browse files
committed
corrected the read methods
1 parent a74638f commit 85a1f01

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/Servo_Hardware_PWM.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -427,15 +427,19 @@ void Servo::writeMicroseconds(int value)
427427
}
428428
}
429429

430-
int read()
431-
{
430+
431+
int Servo::read() {
432432
int angle;
433-
angle = (((180 * (this->readMicroseconds() - this->min)) / (this->max - this->min));
433+
angle = ((180 * (this->readMicroseconds() - this->min)) / (this->max - this->min));
434434
return angle;
435435
}
436436

437-
int readMicroseconds()
438-
{
437+
int Servo::readMicroseconds() {
438+
if (this->servoIndex == INVALID_SERVO_NUMBER)
439+
{
440+
this->pulseWidth = 0;
441+
}
442+
439443
return this->pulseWidth;
440444
}
441445
#endif

0 commit comments

Comments
 (0)