DigitalIn#

Initializing the DigitalIn Class#

A Digital Input is created by using the following constructor:

DigitalIn(port)

This constructor uses one parameter:

Parameter

Description

port

The 3-Wire Port that the Digital Input is connected to, whether it’s a port on the Brain, or a 3-Wire Expander.

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.

Class Methods#

high()#

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

Parameters

Description

callback

A function that will be called when the input is high.

arg

Optional. A tuple that is used to pass arguments to the callback function.

Returns: None.

# 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.

Parameters

Description

callback

A function that will be called when the input is low.

arg

Optional. A tuple that is used to pass arguments to the callback function.

Returns: None.

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