限位开关#

介绍#

限位开关是一种小型数字传感器,用于检测与物体的物理接触。

VEX V5 限位开关。

This page uses limit_switch as the example Limit Switch name. Replace it with your own configured name as needed.

以下是可用方法列表:

  • pressing – Returns whether the specified Limit Switch is currently pressed.

  • pressed – Registers a function to be called whenever the Limit Switch is pressed.

  • released – Registers a function to be called whenever the Limit Switch is released.

构造函数 - 手动初始化限位开关。

  • Limit – Create a Limit Switch.

紧迫#

pressing returns a Boolean indicating whether the Limit Switch is currently being pressed.

  • True – The Limit Switch is being pressed.

  • False – The Limit Switch is not being pressed.

Usage:
limit_switch.pressing()

参数

描述

此方法没有参数。

按下#

# Display a message after limit_switch is pressed
while not limit_switch.pressing():
  pass

brain.screen.print("Limit Switch pressed!")

pressed registers a function to be called whenever the Limit Switch is pressed.

Usage:
limit_switch.pressed(callback, arg)

参数

描述

callback

一个先前定义的函数,当限位开关被按下时执行。

arg

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

def my_function():
  brain.screen.print("Pressed")

# Call my_function whenever limit_switch is pressed
limit_switch.pressed(my_function)

发布#

released registers a function to be called whenever the Limit Switch is released.

Usage:
limit_switch.released(callback, arg)

参数

描述

callback

先前定义的 函数,当限位开关释放时执行。

arg

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

def my_function():
  brain.screen.print("Pressed")

# Call my_function whenever limit_switch is released
limit_switch.released(my_function)

构造函数#

Constructors are used to manually create Limit objects, which are necessary for configuring a Limit Switch outside of VEXcode.

Limit#

Limit creates a Limit Switch.

Usage:
Limit(port)

范围

描述

port

The 3-Wire Port that the Limit Switch 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 Limit Switch in Port A
light_switch = Limit(brain.three_wire_port.a)