digital_in#

Initializing the digital_in Class#

A Digital Input is created by using the following constructor:

The digital_in constructor creates a digital_in object in the specified Three Wire Port:

Parameter

Description

port

The 3-Wire Port that the Digital Input is connected to, whether it’s a port on the Brain, or a 3-Wire Expander.

A Brain or 3-Wire Expander must be created first before they can be used to create an object with the digital_in Class constructor.

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

This digin object will be used in all subsequent examples throughout this API documentation when referring to digital_in class methods.

Class Methods#

high()#

The high(callback) method registers a callback function to be called when the Digital Input is high.

Parameters

Description

callback

A function that will be called when the input is high.

Returns: An instance of the Event class.

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

The low(callback) method registers a callback function to be called when the Digital Input is low.

Parameters

Description

callback

A function that will be called when the input is low.

Returns: An instance of the Event class.

// 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);
}