line#

Initializing the line Class#

A Line Tracker is created by using the following constructor:

The line constructor uses one parameter:

Parameter

Description

port

The 3-Wire Port that the Line Tracker 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 line Class constructor.

// Create the Brain.
brain Brain;
// Construct a Line Tracker "Line" with the line class.
line Line = line(Brain.ThreeWirePort.A);

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

Class Methods#

reflectivity()#

The reflectivity(percentUnits units) command returns the reflectivity measured by the Line Tracker. The reflectivity of the Line Tracker is an estimation based on the raw value of the sensor. A reflectivity of 0% is a raw value of 3000 or greater. A reflectivity of 100% is a raw value of 0.

Parameters

Description

units

The only valid unit for reflectivity is percent.

Returns: A double representing the reflectivity measured by the Line Tracker as a value in the range 0 - 100%.

// Get Line Tracker reflectivity in range of 0 - 100%.
double value = Line.reflectivity();

// Print the reflectivity of the Line Tracker to the
// Brain's screen.
Brain.Screen.print(value);

changed()#

The changed(callback) command registers a callback function for when the value of the Line Tracker changes.

Parameters

Description

callback

The callback function to be called when the value of the Line Tracker changes.

Returns: None.

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

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

  // Run lineChanged when the value of the Line Tracker changes.
  Line.changed(lineChanged);
}