限制#
初始化限制类#
使用以下构造函数创建限位开关:
Limit(port)
此构造函数使用一个参数:
范围 |
描述 |
---|---|
|
必须先创建 Brain 或 3-Wire Expander,然后才能使用 Limit Class 构造函数创建对象。
# 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.
参数 |
描述 |
---|---|
打回来 |
按下限位开关时调用的回调函数。 |
arg |
**可选。**传递给回调函数的参数元组。 |
**返回:**无。
# 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.
参数 |
描述 |
---|---|
打回来 |
当限位开关被释放时调用的回调函数。 |
arg |
**可选。**传递给回调函数的参数元组。 |
**返回:**无。
# 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.