数字输入#

初始化 DigitalIn 类#

使用以下构造函数创建数字输入:

数字输入(端口)

此构造函数使用一个参数:

范围

描述

端口

数字输入连接到的 3 线端口,无论它是 Brain 上的端口,还是 3 线扩展器 上的端口。

必须先创建 Brain3-Wire Expander,然后才能使用 DigitalIn 类构造函数创建对象。

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

当引用 DigitalIn 类方法时,此“digin”对象将在整个 API 文档的所有后续示例中使用。

类方法#

high()#

high(callback, arg) 方法注册一个回调函数,当输入为高时调用。

参数

描述

打回来

当输入为高时将被调用的函数。

arg

**可选。**用于向回调函数传递参数的元组。

**返回:**无。

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

low(callback, arg) 方法注册一个回调函数,当输入为低时调用。

参数

描述

打回来

当输入为低时将调用的函数。

arg

**可选。**用于向回调函数传递参数的元组。

**返回:**无。

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