我正在尝试从 QTRA 8 传感器板上以数字方式读取所有单独的 8 个传感器:
http://www.pololu.com/docs/0J19/all
我遇到的问题是,尽管机器人可以正确读取其位置:
qtra.readLine(sensorValues);
它可以正确读取前 6 个传感器的数字,它不会从前 2 个传感器中读取任何内容。
下面是我为测试它而编写的简化代码。请注意,light7 和 light 8 始终返回 0,即使直接位于黑线之上。我想知道我是否做错了什么,以及有什么方法可以避免手动将 1 或 0 分配给前 2 个传感器的输出。
#include <QTRSensors.h>
#define NUM_SENSORS 8 // number of sensors used
#define NUM_SAMPLES_PER_SENSOR 4 // average 4 analog samples per sensor reading
#define EMITTER_PIN 2 // emitter is controlled by digital pin 2
// sensors 0 through 5 are connected to analog inputs 0 through 5, respectively
QTRSensorsAnalog qtra((unsigned char[]) {A7, A6, A5, A4, A3, A2, A1, A0},
NUM_SENSORS, NUM_SAMPLES_PER_SENSOR, EMITTER_PIN);
unsigned int sensorValues[NUM_SENSORS];
//LIGHTS
int light1 = A0;
int light2 = A1;
int light3 = A2;
int light4 = A3;
int light5 = A4;
int light6 = A5;
int light7 = A6;
int light8 = A7;
void setup(){
pinMode(light1, INPUT);
pinMode(light2, INPUT);
pinMode (light3, INPUT);
pinMode(light4, INPUT);
pinMode(light5, INPUT);
pinMode(light6, INPUT);
pinMode(light7, INPUT);
pinMode(light8, INPUT);
Serial.begin(9600);
}
void loop(){
Serial.print(digitalRead(light1));
Serial.print(".....");
Serial.print(digitalRead(light2));
Serial.print(".....");
Serial.print(digitalRead(light3));
Serial.print(".....");
Serial.print(digitalRead(light4));
Serial.print(".....");
Serial.print(digitalRead(light5));
Serial.print(".....");
Serial.print(digitalRead(light6));
Serial.print(".....");
Serial.print(digitalRead(light7));
Serial.print(".....");
Serial.print(digitalRead(light8));
Serial.println();
}
感谢任何愿意花时间回答这个问题的人......