run

Tell a continuous rotation servo to turn at a certain speed.

servos.P0.run(50)

A continuous rotation servo can turn both clockwise and counter-clockwise. They rotate at a speed from stopped to maximum rotation speed. Normally, a continuous rotation servo interprets an angle value as a speed value. But, by using ||servos:run|| though, you can use a speed percentage value to turn the servo from no speed to full speed (0 to 100 percent). Also, for clockwise rotation, the speed value used is a positive number, speed > 0. If you want to turn the servo in the other direction (counter-clockwise), use a negative percentage value.

Parameters

  • speed: a number which is the percentage (0 to 100) of speed to turn the servo at. Use a positive value (speed > 0) to go clockwise and use a negative value to turn counter-clocwise.

Example

Connect a servo to pin P0. Rotate the servo clockwise at 75 percent of full speed. Wait 3 seconds and then stop the servo.

servos.P0.run(75)
basic.pause(3000)
servos.P0.run(0)

How do servos run their motors to change the position of their arm or shaft? Find out in this MakeCode hardware video:

See also

set pulse, set angle

Brief Guide to Servos

servo