From d814f5790451e33db65ac342c0a1483de4a31630 Mon Sep 17 00:00:00 2001 From: Scott Webster Date: Mon, 13 Aug 2018 12:28:18 -0400 Subject: [PATCH 1/2] Make microseconds_to_angle() consistent with simpleio.Servo() - simpleio.Servo() allows for the fine tuning of pulse length via min_pulse and max_pulse but microseconds_to_angle() formerly ignored those values and used hard coded ones. - That would lead to an inaccurate conversion if fine tuning had been used. - This patch makes use of self.min_pulse and self.max_pulse in order to make correct use of any fine tuning specified during object instantiation. --- simpleio.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simpleio.py b/simpleio.py index 7fdb3ab..3b31298 100644 --- a/simpleio.py +++ b/simpleio.py @@ -220,7 +220,7 @@ def angle(self, degrees): def microseconds_to_angle(self, us): #pylint: disable-msg=no-self-use, invalid-name """Converts microseconds to a degree value""" - return map_range(us, 500, 2500, 0, 180) + return map_range(us, self.min_pulse * 1000, self.max_pulse * 1000, 0, 180) def deinit(self): """Detaches servo object from pin, frees pin""" From 6a3393edabed95181df68a2217e31570058c37c7 Mon Sep 17 00:00:00 2001 From: Scott Webster Date: Mon, 13 Aug 2018 16:39:47 -0400 Subject: [PATCH 2/2] Correct unit of time in the Servo class docstring Docstring erroneously stated that units were in microseconds when they were in fact milliseconds. This patch corrects that. --- simpleio.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/simpleio.py b/simpleio.py index 3b31298..25149c5 100644 --- a/simpleio.py +++ b/simpleio.py @@ -178,8 +178,8 @@ class Servo: Easy control for hobby (3-wire) servos :param ~microcontroller.Pin pin: PWM pin where the servo is located. - :param int min_pulse: Pulse width (microseconds) corresponding to 0 degrees. - :param int max_pulse: Pulse width (microseconds) corresponding to 180 degrees. + :param int min_pulse: Pulse width (milliseconds) corresponding to 0 degrees. + :param int max_pulse: Pulse width (milliseconds) corresponding to 180 degrees. Example for Metro M0 Express: