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

port

El puerto de 3 cables al que está conectado el interruptor de límite, ya sea un puerto en el Cerebro o un Expandedor de 3 cables.

Primero se debe crear un Brain o un 3-Wire Expander antes de poder usarlos para crear un objeto con el constructor de clase Limit.

# 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

llamar de vuelta

La función de devolución de llamada que se llamará cuando se presione el interruptor de límite.

arg

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

llamar de vuelta

La función de devolución de llamada que se llamará cuando se libere el interruptor de límite.

arg

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.