Hi, I have a problem. I can not enter the code to do readings in white lines on black surfaces. Please help me …
The code : examples of the original library “# include <QTRSensors.h>” link pololu.com/docs/0J19/all # 3
#include <QTRSensors.h>
#define NUM_SENSORS 8 // number of sensors used
#define TIMEOUT 2500 // waits for 2500 us for sensor outputs to go low
#define EMITTER_PIN 2 // emitter is controlled by digital pin 2
// sensors 0 through 7 are connected to digital pins 3 through 10, respectively
QTRSensorsRC qtrrc((unsigned char[]) {3, 4, 5, 6, 7, 8, 9, 10},
NUM_SENSORS, TIMEOUT, EMITTER_PIN);
unsigned int sensorValues[NUM_SENSORS];
void setup()
{
delay(500);
int i;
pinMode(13, OUTPUT);
digitalWrite(13, HIGH); // turn on LED to indicate we are in calibration mode
for (i = 0; i < 400; i++) // make the calibration take about 10 seconds
{
qtrrc.calibrate(); // reads all sensors 10 times at 2500 us per read (i.e. ~25 ms per call)
}
digitalWrite(13, LOW); // turn off LED to indicate we are through with calibration
// print the calibration minimum values measured when emitters were on
Serial.begin(9600);
for (i = 0; i < NUM_SENSORS; i++)
{
Serial.print(qtrrc.calibratedMinimumOn[i]);
Serial.print(' ');
}
Serial.println();
// print the calibration maximum values measured when emitters were on
for (i = 0; i < NUM_SENSORS; i++)
{
Serial.print(qtrrc.calibratedMaximumOn[i]);
Serial.print(' ');
}
Serial.println();
Serial.println();
delay(1000);
}
void loop()
{
// read calibrated sensor values and obtain a measure of the line position
// from 0 to 5000, where 0 means directly under sensor 0 or the line was lost
// past sensor 0, 1000 means directly under sensor 1, 200 means directly under sensor 2, etc.
// Note: the values returned will be incorrect if the sensors have not been properly
// calibrated during the calibration phase. To get raw sensor values, call:
// qtra.read(sensorValues);
unsigned int position = qtrrc.readLine(sensorValues);
//qtrrc.read(sensorValues);
// print the sensor values as numbers from 0 to 9, where 0 means maximum reflectance and
// 9 means minimum reflectance, followed by the line position
unsigned char i;
for (i = 0; i < NUM_SENSORS; i++)
{
Serial.print(sensorValues[i] * 10 / 1001);
Serial.print(' ');
}
Serial.print(" ");
Serial.println(position);
delay(250);
}