1.2 KiB
1.2 KiB
Servo Write Pin
Write a value to the servo on the specified pin and control the shaft.
This function will move the shaft of a standard servo to the specified
angle, or set the speed of a continuous rotation servo. (0
specifies
full speed in one direction, 180
specifies full speed in the other,
and approximately 90
specifies no movement.)
pins.servoWritePin(AnalogPin.P0, 180)
Parameters
name
: a string that specifies the pin name (P0
throughP4
, orP10
)value
: a number from0
through180
Examples
Setting the shaft angle to midpoint on a servo
pins.servoWritePin(AnalogPin.P0, 90)
Controlling the shaft by using the tilt information of the accelerometer
basic.forever(() => {
let millig = input.acceleration(Dimensions.X)
// map accelerometer readings to angle
let angle = pins.map(millig, -1023, 1023, 0, 180)
pins.servoWritePin(AnalogPin.P0, angle)
})
Setting the full speed on a continuous servo
pins.servoWritePin(AnalogPin.P0, 0)