@@ -797,20 +797,31 @@ class Motor(SourceMixin, CompositeDevice):
797797 The GPIO pin that the backward input of the motor driver chip is
798798 connected to.
799799
800+ :param int enable:
801+ (Optional) The GPIO pin that enables the motor. Required for some motor
802+ controller boards. Defaults to ``None``.
803+
800804 :param bool pwm:
801805 If ``True`` (the default), construct :class:`PWMOutputDevice`
802806 instances for the motor controller pins, allowing both direction and
803807 variable speed control. If ``False``, construct
804808 :class:`DigitalOutputDevice` instances, allowing only direction
805809 control.
806810 """
807- def __init__ (self , forward = None , backward = None , pwm = True ):
811+ def __init__ (self , forward = None , backward = None , enable = None , pwm = True ):
808812 if not all ([forward , backward ]):
809813 raise GPIOPinMissing (
810814 'forward and backward pins must be provided'
811815 )
812816 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__ (
814825 forward_device = PinClass (forward ),
815826 backward_device = PinClass (backward ),
816827 _order = ('forward_device' , 'backward_device' ))
0 commit comments