Límite#

Inicializando la clase límite#

Un interruptor de límite se crea utilizando el siguiente constructor:

Límite(puerto)

Este constructor utiliza un parámetro:

Parámetro

Descripción

puerto

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)

Este objeto “limit” se utilizará en todos los ejemplos posteriores a lo largo de esta documentación de API cuando se haga referencia a los métodos de la clase Limit.

Métodos de clase#

pressed()#

El método pressed(callback, arg) registra una función de devolución de llamada para cuando se presiona el interruptor de límite.

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()#

El método released(callback, arg) registra una función de devolución de llamada para cuando se libera el interruptor de límite.

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()#

El método pressing() verifica si el interruptor de límite está siendo presionado actualmente.

Devuelve: Verdadero si el interruptor de límite está presionado actualmente. Falso si no lo está.