Skip to content

Commit 3ce587e

Browse files
authored
Merge pull request #34 from brentru/remove-servo
Removing servo class in favor of motor.servo
2 parents 54766df + 84c0157 commit 3ce587e

File tree

1 file changed

+0
-53
lines changed

1 file changed

+0
-53
lines changed

simpleio.py

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -173,59 +173,6 @@ def shift_out(data_pin, clock, value, msb_first=True):
173173
clock.value = True
174174
clock.value = False
175175

176-
class Servo:
177-
"""
178-
Easy control for hobby (3-wire) servos
179-
180-
:param ~microcontroller.Pin pin: PWM pin where the servo is located.
181-
:param int min_pulse: Pulse width (milliseconds) corresponding to 0 degrees.
182-
:param int max_pulse: Pulse width (milliseconds) corresponding to 180 degrees.
183-
184-
Example for Metro M0 Express:
185-
186-
.. code-block:: python
187-
188-
import simpleio
189-
import time
190-
from board import *
191-
192-
pwm = simpleio.Servo(D9)
193-
194-
while True:
195-
pwm.angle = 0
196-
print("Angle: ", pwm.angle)
197-
time.sleep(2)
198-
pwm.angle = pwm.microseconds_to_angle(2500)
199-
print("Angle: ", pwm.angle)
200-
time.sleep(2)
201-
"""
202-
def __init__(self, pin, min_pulse=0.5, max_pulse=2.5):
203-
self.pwm = pulseio.PWMOut(pin, frequency=50)
204-
self.min_pulse = min_pulse
205-
self.max_pulse = max_pulse
206-
self._angle = None
207-
208-
@property
209-
def angle(self):
210-
"""Get and set the servo angle in degrees"""
211-
return self._angle
212-
213-
@angle.setter
214-
def angle(self, degrees):
215-
"""Writes a value in degrees to the servo"""
216-
self._angle = max(min(180, degrees), 0)
217-
pulse_width = self.min_pulse + (self._angle / 180) * (self.max_pulse - self.min_pulse)
218-
duty_percent = pulse_width / 20.0
219-
self.pwm.duty_cycle = int(duty_percent * 65535)
220-
221-
def microseconds_to_angle(self, us): #pylint: disable-msg=no-self-use, invalid-name
222-
"""Converts microseconds to a degree value"""
223-
return map_range(us, self.min_pulse * 1000, self.max_pulse * 1000, 0, 180)
224-
225-
def deinit(self):
226-
"""Detaches servo object from pin, frees pin"""
227-
self.pwm.deinit()
228-
229176
class DigitalOut:
230177
"""
231178
Simple digital output that is valid until reload.

0 commit comments

Comments
 (0)