电位器#
介绍#
电位器是一种模拟传感器,用于测量旋转轴的角位置。它输出的电压与其位置成正比。
根据电位器型号的不同,其可检测的旋转量也不同:
电位器 – 最高可达 250 度
电位器 V2 – 330 度(连续)
|
|
|---|---|
电位器 |
电位器 V2 |
本页面使用 potentiometer_a 作为电位器名称示例。请根据需要将其替换为您自己配置的名称。
以下是可用方法列表:
构造函数 – 手动初始化电位器或电位器 V2。
PotentiometerV2– 创建一个电位器 V2。Potentiometer– 创建一个电位器。
角度#
angle 返回电位器的角度位置,以度或百分比表示。
Usage:
potentiometer_a.angle(units)
范围 |
描述 |
|---|---|
|
计量单位:
|
已更改#
changed 注册一个函数,当电位器的值发生变化时,该函数将被调用。
Usage:
changed(callback, arg)
参数 |
描述 |
|---|---|
|
先前定义的 函数,当电位器的值发生变化时执行。 |
|
def my_function():
brain.screen.print("Value changed!")
# Call my_function whenever potentiometer_a's angle changes
potentiometer_a.changed(my_function)
构造函数#
构造函数用于手动创建 PotentiometerV2 和 Potentiometer 对象,这是在 VEXcode 之外配置电位器所必需的。
PotentiometerV2#
PotentiometerV2 产生 V5 电位器 V2。
Usage:
PotentiometerV2(port)
范围 |
描述 |
|---|---|
|
The 3-Wire Port that the Potentiometer V2 is connected to:
|
# Create a Potentiometer V2 in Port A
potentiometer_a = PotentiometerV2(brain.three_wire_port.a)
Potentiometer#
Potentiometer 创建一个电位器。
Usage:
Potentiometer(port)
范围 |
描述 |
|---|---|
|
The 3-Wire Port that the Potentiometer is connected to:
|
# Create a Potentiometer in Port A
potentiometer_a = Potentiometer(brain.three_wire_port.a)

