Entrada analógica#

Introducción#

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

Constructores de clases#

analog_in( 
  triport::port &port );

Instructor de clase#

Destroys the analog_in object and releases associated resources.

~analog_in();

Parámetros#

Parámetro

Tipo

Descripción

port

triport::port&

The 3-Wire Port that the Analog Input 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).

Ejemplo#

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

Funciones de los miembros#

The analog_in class includes the following member functions:

  • changed — Registers a callback function for when the analog input value changes.

Before calling any analog_in member functions, an analog_in instance must be created, as shown below:

/* This constructor is required to use an
Analog Input device. Replace the values
as needed. */

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

value#

Devuelve el valor actual de la entrada analógica.

Available Functions
int32_t value( 
  analogUnits units );

Parameters

Parámetro

Tipo

Descripción

units

analogUnits

The unit to represent the value:

  • range8bit — 8-bit analog value (a value with 256 possible states)
  • range10bit — 10-bit analog value (a value with 1024 possible states)
  • range12bit — 12-bit analog value (a value with 4096 possible states)
  • pct — percentage
  • mV — millivolts

Return Values

Esta función devuelve el valor actual de la entrada analógica.

Examples
// Get the current value of the Analog Input
int32_t value = AnalogInA.value();

changed#

Registra una función de devolución de llamada que se ejecutará cuando cambie el valor de la entrada analógica.

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

Parameters

Parámetro

Tipo

Descripción

callback

void (* callback)(void)

Una función que se llamará cuando cambie el valor de la entrada analógica.

Return Values

Esta función no devuelve ningún valor.

Examples
// Display a message when the input changes
void AnalogInputChanged() {
  Brain.Screen.print("analog input changed");
}

// Run AnalogInputChanged when the value of the
// Analog Input changes
AnalogInA.changed(AnalogInputChanged);