伺服#

初始化伺服类#

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

Servo(port)

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

范围

描述

port

The 3-Wire Port to use for the Servo Output, whether it’s a port on the Brain, or a 3-Wire Expander.

A Brain or 3-Wire Expander must be created first before they can be used to create an object with the Servo Class constructor.

# 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.

参数

描述

value

伺服的新值。

units

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

**返回:**无。

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