olla#
Inicializando la clase pot#
Un potenciómetro se crea utilizando el siguiente constructor:
The pot
constructor creates a pot object in the specified Three Wire Port:
Parámetro |
Descripción |
---|---|
|
El puerto de 3 cables al que está conectado el potenciómetro, 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 pot.
// Create the Brain.
brain Brain;
// Construct a Potentiometer "potentiometer" with the
// pot class.
pot potentiometer = pot(Brain.ThreeWirePort.A);
This potentiometer
object will be used in all subsequent examples throughout this API documentation when referring to pot class methods.
Métodos de clase#
angle()#
The angle(units)
method returns the angle measured by the Potentiometer.
Parámetros |
Descripción |
---|---|
unidades |
A valid rotationUnit or |
Devuelve: Un doble que representa el ángulo medido por el potenciómetro en las unidades especificadas.
// Get the current angle of the Potentiometer in the
// range 0 - 250 degrees.
double angle = potentiometer.angle(degrees);
// Print the current angle of the Potentiometer to the
// brain screen.
Brain.Screen.print(angle);
changed()#
The changed(callback)
method registers a callback function for when the value measured by the Potentiometer changes.
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. |
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 Potentiometer
// changed on the Brain's screen.
Brain.Screen.print("Potentiometer changed");
}
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
// Run PotentiometerChanged when the value measured by
// the Potentiometer changes.
potentiometer.changed(potentiometerChanged);
}