diff --git a/640.md b/640.md index 5682381..3f69e81 100644 --- a/640.md +++ b/640.md @@ -93,6 +93,48 @@ m1 = dw.getMotor(1) #### Motor driving +There are two main commands that you can give a motor - to move in a direction and to stop. We'll start with the main command to stop the motor + +``` python +m1.off() +``` + +We can also stop the motor by using the second command and passing a speed of 0 + +``` python +m1.setMotorSpeed(0) +``` + +The **setMotorSpeed* command allows you to specify the speed of each motor - there are two different speed ranges the first goes from *-255* to *255*, the second from *1000* to *2000*. + +If you are familiar with radio control vehicles and ESC motors then you will recognise the second range. + +For now we'll concentrate on the first range. + +To get your motor going forwards at full speed you should set its speed at 255 + +``` python +m1.setMotorSpeed(255) +``` + +To get your motor going backwards at full speed you should set its speed to -255 + +``` python +m1.setMotorSpeed(-255) +``` + +The numbers from 0 to the maximum in each direction will drive the motor at a slower speed, so for half speed forwards we'd use + +``` python +m1.setMotorSpeed(125) +``` + +And for a slow speed backwards we can use + +``` python +m1.setMotorSpeed(-50) +``` + #### Select a Servo #### Servo control