Skip to content

Commit a23f2cb

Browse files
committed
corrected the read() method
1 parent a6fa637 commit a23f2cb

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/Servo_Hardware_PWM.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -429,9 +429,18 @@ void Servo::writeMicroseconds(int value)
429429

430430

431431
int Servo::read() {
432-
int angle;
433-
angle = ((180 * (this->readMicroseconds() - this->min)) / (this->max - this->min));
434-
return angle;
432+
float angle;
433+
434+
if ((this->readMicroseconds() - this->min) <= 0)
435+
{
436+
angle = 0.0;
437+
}
438+
else
439+
{
440+
angle = (180.0 / (this->max - this->min)) * (this->readMicroseconds() - this->min);
441+
}
442+
443+
return (int)angle;
435444
}
436445

437446
int Servo::readMicroseconds() {

0 commit comments

Comments
 (0)