伺服#
初始化伺服类#
使用以下构造函数创建伺服输出:
The servo
constructor creates a servo object in the specified Three Wire Port.
范围 |
描述 |
---|---|
|
必须先创建 Brain 或 3-Wire Expander,然后才能使用伺服类构造函数创建对象。
// Create the Brain.
brain Brain;
// Construct a Servo Output "Servo" with the servo class.
servo Servo = servo(Brain.ThreeWirePort.A);
This Servo
object will be used in all subsequent examples throughout this API documentation when referring to servo class methods.
类方法#
setPosition()#
该方法通过以下方式调用:
The setPosition(value, units)
method sets the position of the Servo using a percentage.
参数 |
描述 |
---|---|
价值 |
伺服器的整数值。 |
单位 |
The only valid unit for the units in this usecase is |
**返回:**无。
// Set the servo position to 10 percent.
Servo.setPosition(10, percent);
The setPosition(value, units)
method sets the position of the Servo using a Rotation Unit.
参数 |
描述 |
---|---|
价值 |
伺服器的双倍值。 |
单位 |
有效的 rotationUnit。 |
**返回:**无。
// Set the servo position to 45.5 degrees.
Servo.setPosition(45.5, degrees);