伺服#

初始化伺服类#

使用以下构造函数创建伺服输出:

Servo(port)

此构造函数使用一个参数:

范围

描述

port

用于伺服输出的 3 线端口,无论它是 大脑 上的端口,还是 3 线扩展器 上的端口。

必须先创建 Brain3-Wire Expander,然后才能使用 Servo Class 构造函数创建对象。

# Create the Brain.
brain = Brain()
# Construct a Servo Output "servo" with the Servo class.
servo = Servo(brain.three_wire_port.a)

This Servo object will be used in all subsequent examples throughout this API documentation when referring to Servo class methods.

类方法#

set_position()#

The set_position(value, units) method sets the position of the Servo.

参数

描述

价值

伺服的新值。

单位

Optional. A valid RotationUnits type. The default is PERCENT.

**返回:**无。

# Set the Servo Output to 10 degrees.
servo.set_position(10, DEGREES)