限制#
初始化限制类#
使用以下构造函数创建限位开关:
Limit(port)
此构造函数使用一个参数:
范围 |
描述 |
|---|---|
|
The 3-Wire Port that the Limit Switch is connected to, whether it’s a port on the |
A Brain or 3-Wire Expander must be created first before they can be used to create an object with the Limit Class constructor.
# Create the Brain.
brain = Brain()
# Construct a Limit Switch "limit" with the Limit class.
limit = Limit(brain.three_wire_port.a)
This limit object will be used in all subsequent examples throughout this API documentation when referring to Limit class methods.
类方法#
pressed()#
The pressed(callback, arg) method registers a callback function for when the Limit Switch is pressed.
参数 |
描述 |
|---|---|
|
按下限位开关时调用的回调函数。 |
|
**可选。**传递给回调函数的参数元组。 |
**返回:**无。
# Define a function switch_pressed().
def switch_pressed():
# The Brain will print that the Limit Switch was pressed
# on the Brain's screen.
brain.screen.print("switch pressed")
# Run switch_pressed when the Limit Switch is pressed.
limit.pressed(switch_pressed)
released()#
The released(callback, arg) method registers a callback function for when the Limit Switch is released.
参数 |
描述 |
|---|---|
|
当限位开关被释放时调用的回调函数。 |
|
**可选。**传递给回调函数的参数元组。 |
**返回:**无。
# Define a function switch_released().
def switch_released():
# The Brain will print that the Limit Switch was released
# on the Brain's screen.
brain.screen.print("switch released")
# Run switch_released when the Limit Switch is released.
limit.released(switch_released)
pressing()#
The pressing() method checks if the Limit Switch is currently being pressed.
Returns: True if the Limit Switch is currently being pressed. False if it is not.