Entrada digital#

Inicializando la clase DigitalIn#

Una entrada digital se crea utilizando el siguiente constructor:

DigitalIn(port)

Este constructor utiliza un parámetro:

Parámetro

Descripción

port

El puerto de 3 cables al que está conectada la entrada digital, 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 DigitalIn.

# Create the Brain.
brain = Brain()
# Construct a Digital Input "digin" with the
# DigitalIn class.
digin = DigitalIn(brain.three_wire_port.a)

This digin object will be used in all subsequent examples throughout this API documentation when referring to DigitalIn class methods.

Métodos de clase#

high()#

The high(callback, arg) method registers a callback function to be called when the input is high.

Parámetros

Descripción

llamar de vuelta

Una función que se llamará cuando la entrada sea alta.

arg

Opcional. Una tupla que se utiliza para pasar argumentos a la función de devolución de llamada.

Devoluciones: Ninguna.

# Define function input_high().
def input_high():
    # The Brain will print that the Digital Input is high
    # on the Brain's screen.
    brain.screen.print("digital input high")
# Run input_high() when the Digital Input is high.
digin.high(input_high)

low()#

The low(callback, arg) method registers a callback function to be called when the input is low.

Parámetros

Descripción

llamar de vuelta

Una función que se llamará cuando la entrada sea baja.

arg

Opcional. Una tupla que se utiliza para pasar argumentos a la función de devolución de llamada.

Devoluciones: Ninguna.

# Define function input_low().
def input_low():
    # The Brain will print that the Digital Input is low on
    # the Brain's screen.
    brain.screen.print("digital input low ")
# Run input_low() when the Digital Input is low.
digin.low(input_low)