analog_in#

Initializing the analog_in Class#

An Analog Input is created by using the following constructor:

The analog_in constructor creates an analog_in object in the specified Three Wire Port.

Parameter

Description

port

The 3-Wire Port that the Analog Input is connected to, whether it’s a port on the Brain, or a 3-Wire Expander.

A Brain or 3-Wire Expander must be created first before they can be used to create an object with the analog_in Class constructor.

// Create the Brain.
brain Brain;
// Construct an analog_in "analogIn" with the
// analog_in class.
analog_in analogIn = analog_in(Brain.ThreeWirePort.A);

This analogIn object will be used in all subsequent examples throughout this API documentation when referring to analog_in class methods.

Class Methods#

changed()#

The changed(callback) method registers a function to be called when the value of the analog input changes.

Parameters

Description

callback

A function that will be called when the value of analog input changes.

Returns: An instance of the Event class.

// Define the AnalogInputChanged function with a void return
// type, showing it doesn't return a value.
void AnalogInputChanged() {
  // The Brain will print that the Analog Input changed on
  // the Brain's screen.
  Brain.Screen.print("analog input changed");
}

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

  // Run analogInputChanged when the value of the
  // Analog Input changes.
  analogIn.changed(analogInputChanged);
}