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.P1, 180)
name: a string that specifies the pin name (P0 through P4, or P10)value: a number from 0 through 180pins.servoWritePin(AnalogPin.P1, 90)
basic.forever(() => {
let millig = input.acceleration(Dimension.X)
// map accelerometer readings to angle
let angle = pins.map(millig, -1023, 1023, 0, 180)
pins.servoWritePin(AnalogPin.P1, angle)
})
pins.servoWritePin(AnalogPin.P1, 0)