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 |
|---|---|---|
|
|
The 3-Wire Port that the Digital Input device is connected to, written as |
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 Functionsvoid high(
void (* callback)(void) );
Parameter |
Type |
Description |
|---|---|---|
|
|
A function that will be called when the input is high. |
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 Functionsvoid low(
void (* callback)(void) );
Parameter |
Type |
Description |
|---|---|---|
|
|
A function that will be called when the input is low. |
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);