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 |
|---|---|
|
The 3-Wire Port that the Digital Input 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 DigitalIn Class constructor.
# 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 |
|---|---|
|
Una función que se llamará cuando la entrada sea alta. |
|
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 |
|---|---|
|
Una función que se llamará cuando la entrada sea baja. |
|
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)