线#
初始化线类#
使用以下构造函数创建线跟踪器:
线路(端口)
此构造函数使用一个参数:
范围 |
描述 |
---|---|
|
必须先创建 Brain 或 3-Wire Expander,然后才能使用 Line Class 构造函数创建对象。
# Create the Brain.
brain = Brain()
# Construct a Line Tracker "line" with the Line class.
line = Line(brain.three_wire_port.a)
当引用 Line 类方法时,此“line”对象将在整个 API 文档的所有后续示例中使用。
类方法#
reflectivity()#
reflectivity(units)
方法返回线追踪器测量的反射率。线追踪器的反射率是根据传感器原始值估算的。反射率为 0% 表示原始值大于或等于 3000。反射率为 100% 表示原始值为 0。
参数 |
描述 |
---|---|
单位 |
**可选。**反射率的唯一有效单位是“百分比”。 |
**返回:**线跟踪器测量的反射率,范围为 0 - 100%。
# Print the reflectivity of the Line Tracker to the
# Brain's screen.
brain.screen.print(line.reflectivity())
changed()#
changed(callback, arg)
方法注册一个回调函数,用于当线跟踪器的值发生变化时执行。
参数 |
描述 |
---|---|
打回来 |
当线跟踪器的值改变时调用的回调函数。 |
arg |
**可选。**传递给回调函数的参数元组。 |
**返回:**无。
# 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)