嗨,我正尽力把脑子放在C++和OOP周围。我写了一些代码,在我将其全部放入主循环时,这些代码是有效的。我现在正在整理它,并制作我自己的简单的图书馆和课程。
我的项目有一个8个LED传感器阵列与Arduino 董事会连接。 我正在尝试读取光感应器的状态。 我正在使用QTRSensors 库, 它有一种校准方法, 当我即时给我的班级打电话。
目前我有以下代码。
Header 重
#ifndef SEDIMENTLOGGER_H
#define SEDIMENTLOGGER_H
#include <QTRSensors.h>
#include <Arduino.h>
#define NUM_SENSORS 8
class sedimentSensor
{
public:
QTRSensorsRC sensor1;//(unsigned char [8], int&, int&, int&);
QTRSensorsRC sensor2;//(unsigned char [8], int&, int&, int&);
sedimentSensor(); //default constructor
~sedimentSensor();
void calibrateSensors();
unsigned int *SensorValues1(){return sensorValues1;};
unsigned int *SensorValues2(){return sensorValues2;};
int SampleDelay(){return sampleDelay;};
int EmitterPin1();
unsigned int Position1(){return position1;};
void Position1(unsigned int value){position1 = value;};
unsigned int Position2(){return position2;};
void Position2(unsigned int value){position2 = value;};
private:
// Map pins to LED numbers
// first LED array
int led1;
int led2;
int led3;
int led4;
int led5;
int led6;
int led7;
int led8;
int emitterPin1;
//second Array
int led9;
int led10;
int led11;
int led12;
int led13;
int led14;
int led15;
int led16;
int emitterPin2;
int timeout; // waits for 2.5 seconds for sensor outputs to go low
long sampleDelay; // 1 second
int numSensors;
unsigned int sensorValues1[];
unsigned int sensorValues2[];
unsigned int position1;
unsigned int position2;
};
#endif
我试图在班级执行
#include "sedimentLogger.h"
#include <Arduino.h>
#include <QTRSensors.h>
sedimentSensor::sedimentSensor()
{
//Constructor
led1 = 24;
led2 = 26;
led3 = 28;
led4 = 30;
led5 = 32;
led6 = 34;
led7 = 36;
led8 = 38;
emitterPin1 = 22;
//second Array
led9 = 25;
led10 = 27;
led11 = 29;
led12 = 31;
led13 = 33;
led14 = 35;
led15 = 37;
led16 = 39;
emitterPin2 = 23;
timeout = 2500; // waits for 2.5 seconds for sensor outputs to go low
sampleDelay = 1000; // 1 second
sensorValues1[NUM_SENSORS];
sensorValues2[NUM_SENSORS];
};
sedimentSensor::~sedimentSensor()
{
};
int sedimentSensor::EmitterPin1()
{return emitterPin1;};
void sedimentSensor::calibrateSensors()
{
sensor1((unsigned char[]){led1,led2,led3,led4,led5,led6,led7,led8},numSensors,timeout,emitterPin1);
sensor2((unsigned char[]) {led9,led10,led11,led12,led13,led14,led15,led16},numSensors,timeout,emitterPin2);
unsigned int _delay = 500;
delay(_delay);
pinMode(13,OUTPUT);
for(int i = 0; i<400; i++)
{
sensor1.calibrate();
sensor2.calibrate();
}
digitalWrite(13,LOW);
//TODO WRITE MAX AND MIN VALS TO FILE
Serial.print("Array 1 Min :: ");
for (int i = 0; i < NUM_SENSORS; i++)
{
Serial.print (sensor1.calibratedMinimumOn[i]);
Serial.print( );
}
Serial.println();
Serial.print("Array 2 Min :: ");
for (int i = 0;i< NUM_SENSORS; i++)
{
Serial.print (sensor2.calibratedMinimumOn[i]);
Serial.print( );
}
Serial.println();
Serial.print("array 1 Max :: ");
// print the calibration maximum values measured when emitters were on
for (int i = 0; i < NUM_SENSORS; i++)
{
Serial.print(sensor1.calibratedMaximumOn[i]);
Serial.print( );
}
Serial.println();
Serial.print("array 2 Max :: ");
// print the calibration maximum values measured when emitters were on
for (int
i = 0; i < NUM_SENSORS; i++)
{
Serial.print(sensor2.calibratedMaximumOn[i]);
Serial.print( );
}
Serial.println();
Serial.println();
delay(_delay);
};
我的主要功能和回环
#include <QTRSensors.h>
#include <Arduino.h>
#include "sedimentLogger.h"
#include <Wire.h>
#include "/home/marrabld/Programming/Arduino/arduino-1.0/libraries/RTClib/RTClib.h"
sedimentSensor sedLog;//= sedimentSensor();
void setup()
{
Serial.begin(9600);
sedLog.calibrateSensors();
}
void loop()
{
sedLog.Position1(sedLog.sensor1.readLine(sedLog.SensorValues1()));
sedLog.Position2(sedLog.sensor2.readLine(sedLog.SensorValues2()));
unsigned char i;
for (i = 0; i < NUM_SENSORS; i++)
{
Serial.print(sedLog.SensorValues1()[i] * 10/10001);
Serial.print( );
}
Serial.println(sedLog.Position1());
for (i=0;i < NUM_SENSORS; i++)
{
Serial.print(sedLog.SensorValues2()[i]*10/1001);
Serial.print( );
}
Serial.print(" ");
Serial.println(sedLog.Position2());
delay(sedLog.SampleDelay());
Serial.println(sedLog.SampleDelay());
Serial.println(sedLog.EmitterPin1());
}
我得到以下错误错误
sedimentLogger.cpp: In member function ‘void sedimentSensor::calibrateSensors()’: sedimentLogger.cpp:47:102: error: no match for call to ‘(QTRSensorsRC) (unsigned char [8], int&, int&, int&)’ sedimentLogger.cpp:48:108: error: no match for call to ‘(QTRSensorsRC) (unsigned char [8], int&, int&, int&)’
我尝试了几种不同的变异 比如把感应器的即时反应 放到我的沉积感应器里 和一堆其他的没有运气的东西
我希望得到任何帮助和建议,使这项工作得以进行,我在这里显然也缺少一个概念,因此,任何辅导建议同样会有帮助。