@@ -512,6 +512,22 @@ def motor_move(self, direction='forward'):
512512 else :
513513 raise TypeError
514514 Runner .wait (100 ) # Since broadcast from controller is per 100ms
515+
516+ def motor_stop (self , which_motor : str ):
517+ if isinstance (which_motor , str ):
518+ if which_motor .lower () == 'right' :
519+ self .write (Neosoco .RIGHT_MOTOR , 0 )
520+ elif which_motor .lower () == 'left' :
521+ self .write (Neosoco .LEFT_MOTOR , 0 )
522+ elif which_motor .lower () == 'both' :
523+ self .write (Neosoco .LEFT_MOTOR , 0 )
524+ self .write (Neosoco .RIGHT_MOTOR , 0 )
525+ else :
526+ Runner .shutdown () # The motor will not stop unless the shutdown() function is used
527+ raise ValueError ('Wrong value of motor' )
528+ else :
529+ Runner .shutdown () # The motor will not stop unless the shutdown() function is used
530+ raise TypeError
515531
516532 def _convert_sacle_within_100 (self , value , cvt_max_val ):
517533 # Map to 0~limited_val from 0~100(max), it's same as Entry
@@ -706,4 +722,4 @@ def buzzer_by_port(self, port='in1'):
706722 value = self ._convert_scale_from_input_port (port , 65 )
707723 self .write (Neosoco .NOTE , value )
708724 else :
709- raise TypeError
725+ raise TypeError
0 commit comments