激光触发槽车圈速计时器:GLCD 显示的高精度 RC 赛道计时
组件与物料
- Arduino Mega 2560 ×1
- KY-008 激光发射模块 ×1
- 激光接收传感器(配套 KY-008)×1
- 128×64 图形 LCD(KS0108 控制器,OpenGLCD 库兼容)×1
软件与库
- Arduino IDE
- OpenGLCD 库:Bitbucket(支持 KS0108 并行接口)
项目简介
在槽车赛道终点线架设激光对射光栅:车辆通过遮挡光束 → 接收端信号翻转 → Arduino 捕获下降沿 → 计算单圈用时、最佳圈速、累计圈数,实时在 GLCD 上以大号数字字体显示。消抖 50 ms 避免车身抖动误触发。
硬件接线
- 激光模块:VCC/信号脚并接 5V(常亮),GND 接地。如需控制开关,信号脚接数字口。
- 接收模块:VCC/GND 接电源,SIGNAL 接 Arduino Mega D2(外部中断脚)。
- GLCD:并行接口需 13 根信号线,按 OpenGLCD 文档接线;作者自制排针转接座简化连接。
核心代码逻辑
#include
const int GATE_PIN = 2;
int gateState, lastGateState = LOW;
unsigned long lastDebounce = 0;
const int DEBOUNCE_MS = 50;
unsigned long lapStart = 0, lastLap = 0, bestLap = 0;
int lapCount = 0;
gText tLap(0,0), tLast(0,1), tBest(1,1); // 定义显示区域
void setup() {
pinMode(GATE_PIN, INPUT);
delay(50); // 等待激光稳定
GLCD.Init(NON_INVERTED);
// 字体、区域、标题初始化...
}
void loop() {
int reading = digitalRead(GATE_PIN);
if (reading != lastGateState) lastDebounce = millis();
if (millis() - lastDebounce > DEBOUNCE_MS) {
if (reading != gateState) {
gateState = reading;
if (gateState == LOW) { // 光束被遮挡
unsigned long now = millis();
if (lapCount > 0) {
lastLap = now - lapStart;
if (lastLap < bestLap || bestLap == 0) bestLap = lastLap;
}
lapStart = now;
lapCount++;
}
}
}
lastGateState = reading;
// 实时刷新显示
updateDisplay(lapCount, millis()-lapStart, lastLap, bestLap);
}
显示布局
- 顶部大号字体:圈数(2 位)+ 当前圈计时(秒.毫秒)
- 左下:LAST 圈时间
- 右下:BEST 最快圈时间
调试要点
- 激光与接收器必须精准对齐,建议用可调支架微调。
- 消抖时间可根据车速调整(更快的车缩短至 20–30 ms)。
- GLCD 并行接线繁多,建议做专用排线或 PCB 转接板。
制造工艺