Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

servo: Add function SetAngleWithMicroseconds #695

Merged
merged 2 commits into from
Oct 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions servo/servo.go
Original file line number Diff line number Diff line change
@@ -102,3 +102,16 @@ func (s Servo) SetAngle(angle int) error {

return nil
}

// SetAngleWithMicroseconds sets the angle of the servo in degrees. The angle should be between
// 0 and 180, where 0 is the minimum angle and 180 is the maximum angle.
// The high duration can be customized
// 0° is lowMicroseconds(us), 180° is highMicroseconds(us)
func (s Servo) SetAngleWithMicroseconds(angle int, lowMicroseconds, highMicroseconds int) error {
if angle < 0 || angle > 180 {
return ErrInvalidAngle
}
microseconds := lowMicroseconds + (highMicroseconds-lowMicroseconds)*angle/180
s.SetMicroseconds(int16(microseconds))
return nil
}
Loading