Can’t seem to get calibrate to work (just prints 2,500 for each sensor) and also, read() just outputs 0. If I use the QTRCCExample file then both work. My code is as follows:
sensor.ino
#include <QTRSensors.h>
#include "sensor.h"
// Initialize the sensor class
sensor sensor(2500, 2);
void setup()
{
// initialize serial:
Serial.begin(9600);
sensor.setup();
sensor.calibrate();
}
void loop()
{
sensor.run();
}
sensor.h
#include <QTRSensors.h>
#include <Arduino.h>
class sensor
{
public:
sensor(short sensorTimeout, short emitterPin);
~sensor();
void setup();
void calibrate();
void run();
private:
short _sensorTimeout;
short _emitterPin;
QTRSensorsRC _arraySensors;
unsigned int _sensorValues[6];
};
sensor.cpp
#include "sensor.h"
sensor::sensor(short sensorTimeout, short emitterPin) :
_sensorTimeout(sensorTimeout), _emitterPin(emitterPin)
{
}
sensor::~sensor() {}
void sensor::setup()
{
unsigned char mainSensorArray[] = { 31, 33, 35, 37, 39, 41 };
QTRSensorsRC _arraySensors(mainSensorArray, 6, 2500, 2);
}
void sensor::run()
{
_arraySensors.read(_sensorValues);
for (int i = 0; i < 6; i++)
{
Serial.print(_sensorValues[i]);
Serial.print('\t');
return;
}
delay(500);
}
void sensor::calibrate()
{
for (int i = 0; i < 500; i++) //calibrate for sensors over full white/full black)
{
_arraySensors.calibrate(); // reads each sensor 10 times at 2500 us per read
}
}
I can’t personally work out what is going wrong. Any pointers?