电位器#

介绍#

电位器是一种模拟传感器,用于测量旋转轴的角位置。它输出的电压与其位置成正比。

根据电位器型号的不同,其可检测的旋转量也不同:

  • 电位器 – 最高可达 250 度

  • 电位器 V2 – 330 度(连续)

VEX V5 电位器 V1.

VEX V5 电位器 V2.

电位器

电位器 V2

This page uses potentiometer_a as the example Potentiometer name. Replace it with your own configured name as needed.

以下是可用方法列表:

  • angle – Reports the angular position of the Potentiometer in degrees or as a percent.

  • changed – Registers a function to be called whenever the Potentiometer’s value changes.

构造函数 – 手动初始化电位器或电位器 V2。

角度#

angle returns the angular position of the Potentiometer.

Usage:
potentiometer_a.angle(units)

范围

描述

单位

The unit of measurement:

  • DEGREES (default)
    • 0.0 to 250.0 for a Potentiometer
    • 0.0 to 330.0 for a Potentiometer V2
  • PERCENT – The position as a percentage of full rotation (0 to 100%)

已更改#

changed registers a function to be called whenever the Potentiometer’s value changes.

Usage:
changed(callback, arg)

参数

描述

callback

先前定义的 函数,当电位器的值发生变化时执行。

arg

可选。包含要传递给回调函数的参数的元组。有关更多信息,请参阅带参数的函数

def my_function():
  brain.screen.print("Value changed!")

# Call my_function whenever potentiometer_a's angle changes
potentiometer_a.changed(my_function)

构造函数#

Constructors are used to manually create PotentiometerV2 and Potentiometer objects, which are necessary for configuring Potentiometers outside of VEXcode.

PotentiometerV2#

PotentiometerV2 creates a V5 Potentiometer V2.

Usage:
PotentiometerV2(port)

范围

描述

port

The 3-Wire Port that the Potentiometer V2 is connected to:

  • On the V5 Brainbrain.three_wire_port.x where x is the number of the port.
  • On a 3-Wire Expanderexpander.a where expander is the name of the expander instance.

# Create a Potentiometer V2 in Port A
potentiometer_a = PotentiometerV2(brain.three_wire_port.a)

Potentiometer#

Potentiometer creates a Potentiometer.

Usage:
Potentiometer(port)

范围

描述

port

The 3-Wire Port that the Potentiometer is connected to:

  • On the V5 Brainbrain.three_wire_port.x where x is the number of the port.
  • On a 3-Wire Expanderexpander.a where expander is the name of the expander instance.

# Create a Potentiometer in Port A
potentiometer_a = Potentiometer(brain.three_wire_port.a)