数字输入#
初始化 DigitalIn 类#
使用以下构造函数创建数字输入:
DigitalIn(port)
此构造函数使用一个参数:
范围 |
描述 |
---|---|
|
必须先创建 Brain 或 3-Wire Expander,然后才能使用 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.
类方法#
high()#
The high(callback, arg)
method registers a callback function to be called when the input is high.
参数 |
描述 |
---|---|
打回来 |
当输入为高时将被调用的函数。 |
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()#
The low(callback, arg)
method registers a callback function to be called when the input is low.
参数 |
描述 |
---|---|
打回来 |
当输入为低时将调用的函数。 |
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)