0
我試圖從QTRA 8-感應板數字方式讀取所有單獨的8個傳感器:錯誤而數字讀取傳感器
http://www.pololu.com/docs/0J19/all
我得到的問題是,雖然機器人可以讀取其正確位置:
qtra.readLine(sensorValues);
,它可以數字正確讀取第6個傳感器,它不會從第一2.
下面你有m個讀什麼y我編寫的簡化代碼來測試。請注意,即使直接位於黑線上方,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();
}
感謝的人誰都會花時間來回答這個...
在什麼Arduino板,你跑步嗎?它是如何連線的? – Sibster