数字输入#

介绍#

The digital_in class is used to read digital input signals from devices connected to a VEX V5 3-Wire port. It provides access to the current signal state and allows callback functions to be registered for input state changes.

类构造函数#

digital_in( 
  triport::port &port );

类析构函数#

Destroys the digital_in object and releases associated resources.

~digital_in();

参数#

范围

类型

描述

port

triport::port &

The 3-Wire Port that the Digital Input device is connected to, written as Brain.ThreeWirePort.X or ExpanderName.X, where X is the port letter (for example, Brain.ThreeWirePort.A or Expander1.A).

例子#

// Create the digital_in instance on 3-Wire Port A
digital_in digin = digital_in(Brain.ThreeWirePort.A);

成员功能#

The digital_in class includes the following member functions:

  • value — Returns the current state of the digital input.

  • high — Registers a function to be called whenever the Digital In device sends a high signal.

  • low — Registers a function to be called whenever the Digital Out device sends a low signal.

Before calling any digital_in member functions, a digital_in instance must be created, as shown below:

/* This constructor is required when using VS Code.
Digital input configuration is generated automatically
in VEXcode using the Device Menu. Replace the values
as needed. */

// Create the digital_in instance on 3-Wire Port A
digital_in DigitalInA = digital_in(Brain.ThreeWirePort.A);

value#

返回数字输入的当前状态。

可用功能

int32_t value();

参数

此函数不接受任何参数。

返回值

Returns an int32_t representing the current digital signal state:

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

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

high#

注册一个函数,当数字输入设备发送高电平信号(约 5V)时,该函数将被调用。

Available Functions
void high( 
  void (* callback)(void) );

Parameters

范围

类型

描述

callback

void (* callback)(void)

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

Return Values

此函数不返回值。

Examples
// Display that the input is high
void inputHigh() {
  Brain.Screen.print("digital input high");
}

// Run inputHigh when the Digital Input is high
DigitalInA.high(inputHigh);

low#

注册一个函数,当数字输出设备发送低信号(约 0V)时,该函数将被调用。

Available Functions
void low( 
  void (* callback)(void) );

Parameters

范围

类型

描述

callback

function

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

Return Values

此函数不返回值。

Examples
// Display that the input is low
void inputLow() {
  Brain.Screen.print("digital input low");
}


// Run inputLow when the Digital Input is low
DigitalInA.low(inputLow);