Digital In#

Introduction#

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.

Class Constructors#

digital_in( 
  triport::port &port );

Class Destructor#

Destroys the digital_in object and releases associated resources.

~digital_in();

Parameters#

Parameter

Type

Description

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).

Example#

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

Member Functions#

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#

Returns the current state of the digital input.

Available Functions

int32_t value();

Parameters

This function does not accept any parameters.

Return Values

Returns an int32_t representing the current digital signal state:

  • 1 – The Digital In port is receiving a high signal (approximately 5V).

  • 0 – The Digital In port is receiving a low signal (approximately 0V).

high#

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

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

Parameters

Parameter

Type

Description

callback

void (* callback)(void)

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

Return Values

This function does not return a value.

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#

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

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

Parameters

Parameter

Type

Description

callback

function

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

Return Values

This function does not return a value.

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