We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
SetAngleWithMicroseconds
1 parent ce80e75 commit 1c2b802Copy full SHA for 1c2b802
servo/servo.go
@@ -102,3 +102,16 @@ func (s Servo) SetAngle(angle int) error {
102
103
return nil
104
}
105
+
106
+// SetAngleWithMicroseconds sets the angle of the servo in degrees. The angle should be between
107
+// 0 and 180, where 0 is the minimum angle and 180 is the maximum angle.
108
+// The high duration can be customized
109
+// 0° is lowMicroseconds(us), 180° is highMicroseconds(us)
110
+func (s Servo) SetAngleWithMicroseconds(angle int, lowMicroseconds, highMicroseconds int) error {
111
+ if angle < 0 || angle > 180 {
112
+ return ErrInvalidAngle
113
+ }
114
+ microseconds := lowMicroseconds + (highMicroseconds-lowMicroseconds)*angle/180
115
+ s.SetMicroseconds(int16(microseconds))
116
+ return nil
117
+}
0 commit comments