potV2#

Inicializando la clase potV2#

Un PotenciómetroV2 se crea utilizando el siguiente constructor:

El constructor potV2 crea un objeto potV2 en el puerto de tres cables especificado:

Parámetro

Descripción

puerto

El puerto de 3 cables al que está conectado el potenciómetro V2, ya sea un puerto en el Cerebro o un Expandedor de 3 cables.

Primero se debe crear un Brain o un 3-Wire Expander antes de poder usarlos para crear un objeto con el constructor de clase potV2.

// Create the Brain.
brain Brain;
// Construct a PotentiometerV2 "potentiometerV2" with the potV2 class.
potV2 potentiometerV2 = potV2(Brain.ThreeWirePort.A);

Este objeto potentiometerV2 se utilizará en todos los ejemplos posteriores a lo largo de esta documentación de API cuando se haga referencia a los métodos de la clase potV2.

Métodos de clase#

ángulo()#

El método angle(units) devuelve el ángulo medido por el PotenciómetroV2.

Parámetros

Descripción

unidades

Una rotationUnit o un porcentaje válidos. El valor predeterminado es grados.

Devuelve: Un doble que representa el ángulo medido por el potenciómetro V2 en las unidades especificadas.

// Get the current angle of the PotentiometerV2 in the
// range 0 - 250 degrees.
double angle = potentiometerV2.angle(degrees);

// Print the current angle of the PotentiometerV2 to the
// Brain's screen.
Brain.Screen.print(angle);

cambió()#

El método changed(callback) registra una función de devolución de llamada para cuando cambia el valor medido por el PotenciómetroV2.

Parámetros

Descripción

llamar de vuelta

La función de devolución de llamada que se llamará cuando cambie el valor medido por el potenciómetro V2.

Devoluciones: Ninguna.

// Define the potentiometerChanged function with a void
// return type, showing it doesn't return a value.
void potentiometerChanged() {
  // The brain will print that the value of the PotentiometerV2
  // changed on the Brain's screen.
  Brain.Screen.print("PotentiometerV2 changed");
}

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

  // Run potentiometerChanged when the value measured by
  // the PotentiometerV2 changes.
  potentiometerV2.changed(potentiometerChanged);
}