Line#
Initializing the Line Class#
A Line Tracker is created by using the following constructor:
Line(port)
This constructor uses one parameter:
Parameter |
Description |
---|---|
|
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(brain.three_wire_port.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(units)
method 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 |
Optional. The only valid unit for reflectivity is |
Returns: The reflectivity measured by the Line Tracker as a value in the range 0 - 100%.
# Print the reflectivity of the Line Tracker to the
# Brain's screen.
brain.screen.print(line.reflectivity())
changed()#
The changed(callback, arg)
method 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. |
arg |
Optional. A tuple of arguments to pass to the callback function. |
Returns: None.
# Define a function line_changed().
def line_changed():
# The Brain will print that the value detected by the
# Line Tracker changed on the Brain's screen.
brain.screen.print("Line Tracker changed")
# Run line_changed when the value of the Line Tracker changes.
line.changed(line_changed)