commit 65948bf041fe58c6f027d48db9fa76a8696cf4e8 Author: YinMo19 Date: Wed Jun 11 09:16:50 2025 +0800 [initial] first commit diff --git a/infratrack.ino b/infratrack.ino new file mode 100644 index 0000000..4da1a51 --- /dev/null +++ b/infratrack.ino @@ -0,0 +1,39 @@ +// 定义传感器引脚 +const int sensorPins[8] = {A0, A1, A2, A3, A4, A5, A6, A7}; + +// 传感器阈值(根据实际情况调整) +const int threshold = 500; + +void setup() { + // 初始化串口通信 + Serial.begin(9600); + + // 传感器引脚默认是模拟输入,无需设置 +} + +void loop() { + // 读取所有传感器值 + int sensorValues[8]; + for (int i = 0; i < 8; i++) { + sensorValues[i] = analogRead(sensorPins[i]); + } + + // 打印原始传感器值 + Serial.print("Raw Values: "); + for (int i = 0; i < 8; i++) { + Serial.print(sensorValues[i]); + Serial.print("\t"); + } + + // 判断并打印传感器状态(0:检测到黑线, 1:检测到白色背景) + Serial.print(" | States: "); + for (int i = 0; i < 8; i++) { + int state = (sensorValues[i] > threshold) ? 1 : 0; + Serial.print(state); + Serial.print("\t"); + } + + Serial.println(); // 换行 + + delay(100); // 控制数据刷新频率 +}