[initial] first commit

This commit is contained in:
YinMo19 2025-06-11 09:16:50 +08:00
commit 65948bf041

39
infratrack.ino Normal file
View File

@ -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); // 控制数据刷新频率
}