数字输入#

初始化digital_in类#

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

digital_in 构造函数在指定的三线端口中创建一个 digital_in 对象:

范围

描述

端口

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

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

// Create the Brain.
brain Brain;
// Construct a Digital Input "digin" with the
// digital_in class.
digital_in digin = digital_in(Brain.ThreeWirePort.A);

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

类方法#

高的()#

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

参数

描述

打回来

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

**返回:**事件类的一个实例。

// Define the inputHigh function with a void return
// type, showing it doesn't return a value.
void inputHigh() {
  // The Brain will print that the Digital Input is high
  // on the Brain's screen.
  Brain.Screen.print("digital input high");
}

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

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

低的()#

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

参数

描述

打回来

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

**返回:**事件类的一个实例。

// Define the inputLow function with a void return type,
// showing it doesn't return a value.
void inputLow() {
  // The Brain will print that the Digital Input is low
  // on the Brain's screen.
  Brain.Screen.print("digital input low");
}

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

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