Límite#
Inicializando la clase límite#
Un interruptor de límite se crea utilizando el siguiente constructor:
Limit(port)
Este constructor utiliza un parámetro:
Parámetro |
Descripción |
|---|---|
|
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.
Métodos de clase#
pressed()#
The pressed(callback, arg) method registers a callback function for when the Limit Switch is pressed.
Parámetros |
Descripción |
|---|---|
|
La función de devolución de llamada que se llamará cuando se presione el interruptor de límite. |
|
Opcional. Una tupla de argumentos para pasar a la función de devolución de llamada. |
Devoluciones: Ninguna.
# 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.
Parámetros |
Descripción |
|---|---|
|
La función de devolución de llamada que se llamará cuando se libere el interruptor de límite. |
|
Opcional. Una tupla de argumentos para pasar a la función de devolución de llamada. |
Devoluciones: Ninguna.
# 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.