数字输入#

介绍#

V5 主控模块的“数字输入”三线设备允许其读取来自外部信号源(例如开关或传感器)的数字信号。它检测输入线是高电平(接收到 5V)还是低电平(接收到 0V)。这可用于确定设备的开/关状态或触发项目中的事件。

This page uses dig_in as the example Digital In device name. Replace it with your own configured name as needed.

以下是可用方法列表:

  • value – Returns an integer indicating whether the received signal is high or low.

  • high – Registers a function to be called whenever the Digital In device sends a high signal (approximately 5V).

  • low – Registers a function to be called whenever the Digital In device sends a low signal (approximately 0V).

构造函数 – 手动初始化和配置数字输入设备。

价值#

value returns an integer indicating whether the received signal is a high or low.

  • 1 – 数字输入端口接收到高电平信号(约 5V)。

  • 0 – 数字输入端口接收到低信号(大约 0V)。

Usage:
dig_in.value()

参数

描述

此方法没有参数。

高的#

high registers a function to be called whenever the Digital In device sends a high signal (approximately 5V).

Usage:
dig_in.high(callback, arg)

参数

描述

callback

先前定义的函数,当接收到高电平信号时执行。

arg

可选。包含要传递给回调函数的参数的元组。有关更多信息,请参阅带参数的函数

def my_function():
  brain.screen.print("High")

# Call my_function whenever dig_in is high
dig_in.high(my_function)

低的#

low registers a function to be called whenever the Digital In device sends a low signal (approximately 0V).

Usage:
dig_in.low(callback, arg)

参数

描述

callback

先前定义的函数,当接收到低信号时执行。

arg

可选。包含要传递给回调函数的参数的元组。有关更多信息,请参阅带参数的函数

def my_function():
  brain.screen.print("Low")

# Call my_function whenever dig_in is low
dig_in.low(my_function)

构造函数#

Constructors are used to manually create DigitalIn objects, which are necessary for configuring a Digital In device outside of VEXcode.

DigitalIn#

DigitalIn creates a Digital In device.

Usage:
DigitalIn(port)

范围

描述

port

The 3-Wire Port that the Digital In device is connected to:

  • On the V5 Brainbrain.three_wire_port.x where x is the number of the port.
  • On a 3-Wire Expanderexpander.a where expander is the name of the expander instance.

# Create a Digital In device in Port A
dig_in = DigitalIn(brain.three_wire_port.a)