@@ -797,20 +797,31 @@ class Motor(SourceMixin, CompositeDevice):
797
797
The GPIO pin that the backward input of the motor driver chip is
798
798
connected to.
799
799
800
+ :param int enable:
801
+ (Optional) The GPIO pin that enables the motor. Required for some motor
802
+ controller boards. Defaults to ``None``.
803
+
800
804
:param bool pwm:
801
805
If ``True`` (the default), construct :class:`PWMOutputDevice`
802
806
instances for the motor controller pins, allowing both direction and
803
807
variable speed control. If ``False``, construct
804
808
:class:`DigitalOutputDevice` instances, allowing only direction
805
809
control.
806
810
"""
807
- def __init__ (self , forward = None , backward = None , pwm = True ):
811
+ def __init__ (self , forward = None , backward = None , enable = None , pwm = True ):
808
812
if not all ([forward , backward ]):
809
813
raise GPIOPinMissing (
810
814
'forward and backward pins must be provided'
811
815
)
812
816
PinClass = PWMOutputDevice if pwm else DigitalOutputDevice
813
- super (Motor , self ).__init__ (
817
+ if enable :
818
+ super (Motor , self ).__init__ (
819
+ forward_device = PinClass (forward ),
820
+ backward_device = PinClass (backward ),
821
+ enable_device = DigitalOutputDevice (enable , initial_value = True ),
822
+ _order = ('forward_device' , 'backward_device' , 'enable_device' ))
823
+ else :
824
+ super (Motor , self ).__init__ (
814
825
forward_device = PinClass (forward ),
815
826
backward_device = PinClass (backward ),
816
827
_order = ('forward_device' , 'backward_device' ))
0 commit comments