循迹传感器(数字) ===================== .. figure:: /_static/products/ledong-module/static/图片/循迹传感器.png :width: 55% :align: center 概述 -------------------- 可用于循迹线检测,当检测到黑色时,输出高电平,检测白色时,输出低电平。 基于红外反射原理,红外发射二极管不断发射红外线,红外光电三极管接收反射回来的红外光。由于白色对红外反射强,黑色对红外反射弱,故此可检测黑、白线。 技术参数 ------------------- 工作电压: VCC 3.3V -5V 模块尺寸:24*48mm 固定安装:2个兼容塑料积木通孔 数据类型:黑色--1 白色--0 探测距离:0.5-1cm 引脚定义 ------------------- ===== ======== 引脚 定义 ===== ======== GND 地 VCC 电源 D1 D1触发值 D2 D2触发值 ===== ======== 示例程序 ------------------- **1、在安装循迹模块时约距离循迹线1CM左右;** **2、循迹线的宽度至少15mm;** **3、可用黑色电工胶带DIY循迹线,效果较好。** .. code-block:: python from mpython import * p13 = MPythonPin(13, PinMode.IN) p14 = MPythonPin(14, PinMode.IN) from mpython import ledong_shield def boolean_P13(): return p13.read_digital() == 1 def boolean_P14(): return p14.read_digital() == 1 while True: if boolean_P13() and boolean_P14(): ledong_shield.set_motor(1, -60) ledong_shield.set_motor(2, 60) elif boolean_P13() and not boolean_P14(): ledong_shield.set_motor(1, 10) ledong_shield.set_motor(2, 60) elif boolean_P14() and not boolean_P13(): ledong_shield.set_motor(1, -60) ledong_shield.set_motor(2, -10) elif not boolean_P13() and not boolean_P14(): ledong_shield.set_motor(1, -0) ledong_shield.set_motor(2, 0) .. figure:: /_static/products/ledong-module/static/examples/循迹1.png :width: 100% :align: center