Error while digital reading sensors
Question
I'm trying to digitally read all separate 8 sensors from a QTRA 8-sensor board:
http://www.pololu.com/docs/0J19/all
The problem I'm getting is that although the robot can read its position correctly:
qtra.readLine(sensorValues);
and it can read the first 6 sensors digitally correctly, it doesn't read anything from the first 2.
Below you have my simplified code that I wrote to test this out. Note that light7 and light 8 always return 0, even when directly on top of the black line. I'd like to know if there's anything I'm doing wrong and any way to avoid manually assigning 1 or 0 to the outputs of those first 2 sensors.
#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();
}
Thanks to anyone who will take the time to answer this...
Solution
The problem was that the sensors are designed in one 2 - sensor module and another 6 - sensor module.
I had to artificially introduce "digital read" by comparing values from the analogRead function.
i.e.
if(analogRead(light7) > value){
return 1;
}else{
return 0;
}