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

本页面使用 limit_switch 作为限位开关名称示例。您可以根据需要将其替换为您自己配置的名称。
以下是可用方法列表:
构造函数 - 手动初始化限位开关。
Limit– 创建一个限位开关。
紧迫#
pressing 返回 Boolean,指示限位开关当前是否被按下。这可用于检查机器人是否碰撞到其他物体。
True– 限位开关被按下。False– 限位开关未被按下。
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 注册一个函数,该函数会在限位开关被按下时调用。
Usage:
limit_switch.pressed(callback, arg)
参数 |
描述 |
|---|---|
|
一个先前定义的函数,当限位开关被按下时执行。 |
|
def my_function():
brain.screen.print("Pressed")
# Call my_function whenever limit_switch is pressed
limit_switch.pressed(my_function)
发布#
released 注册一个函数,该函数将在限位开关释放时调用。
Usage:
limit_switch.released(callback, arg)
参数 |
描述 |
|---|---|
|
先前定义的 函数,当限位开关释放时执行。 |
|
def my_function():
brain.screen.print("Pressed")
# Call my_function whenever limit_switch is released
limit_switch.released(my_function)
构造函数#
构造函数用于手动创建 Limit 对象,这是在 VEXcode 之外配置限位开关所必需的。
Limit#
Limit 创建限位开关。
Usage:
Limit(port)
范围 |
描述 |
|---|---|
|
The 3-Wire Port that the Limit Switch is connected to:
|
# Create a Limit Switch in Port A
light_switch = Limit(brain.three_wire_port.a)