18. 循迹传感器

18.1. 概述

颜色循迹传感器可用于循迹线检测,基于红外反射原理,红外发射二极管不断发射红外线,红外光电三极管接收反射回来的红外光。由于白色对红外反射强,黑色对红外反射弱,故此可检测黑、白线。

../../_images/11-1.jpg
技术规格
  • 工作电源:3.3V
  • 有效测距量程:1~8mm
  • 尺寸:20mm x 53.5mm
  • 接口类型 :I2C直插接口
  • 设备类型:输入设备
接口定义
  • V:电源正极
  • G:电源负极
  • SDA:双向数据线
  • SCL::时钟线

18.2. 案例程序

图形化:
../../_images/11-2.png
代码:
from mpython import *

from nplus import *

import time

line=Line()
while True:
    oled.fill(0)
    oled.DispChar(str('左一:') + str(line.0()), 0, 0, 1)
    oled.DispChar(str('左二:') + str(line.1()), 0, 16, 1)
    oled.DispChar(str('右一:') + str(line.2()), 0, 32, 1)
    oled.DispChar(str('右二:') + str(line.3()), 0, 48, 1)
    oled.show()
    time.sleep(1)