Hello, I am trying to replicate this formula but it is going wrong in compilation with this message "Can not be use as a function".
Error (t) = sensor1 - sensor2
Error (t) = Error (i + 1) - Error (t)
int i = 0;
const int ldrPin0 = A0;
const int ldrPin1 = A1;
const int Erro(i);
const int dErro(i);
void setup() {
Serial.begin(9600);
pinMode(ldrPin0 , INPUT);
pinMode(ldrPin1 , INPUT);
}
void loop() {
while(i>=0){
Erro(i) = analogRead(ldrPin0) - analogRead(ldrPin1);
dErro(i) = Erro(i + 1) - Erro(i);}
Serial.println(Erro);
Serial.println(dErro);
}
I'm a beginner.
Adriel132:
Hello, I am trying to replicate this formula but it is going wrong in compilation with this message "Can not be use as a function".
Error (t) = sensor1 - sensor2
Error (t) = Error (i + 1) - Error (t)
int i = 0;
const int ldrPin0 = A0;
const int ldrPin1 = A1;
const int Erro(i);
const int dErro(i);
void setup() {
Serial.begin(9600);
pinMode(ldrPin0 , INPUT);
pinMode(ldrPin1 , INPUT);
}
void loop() {
while(i>=0){
Erro(i) = analogRead(ldrPin0) - analogRead(ldrPin1);
dErro(i) = Erro(i + 1) - Erro(i);}
Serial.println(Erro);
Serial.println(dErro);
}
I'm a beginner.
Perhaps it's because you don't ever define "Error" as anything, ever.
Paul
Or perhaps it's because "const int Erro(i);" is meaningless. What did you think that would do? Perhaps you were thinking of an array?
Also declaring things as "const", i.e. read-only, constant, never changes, and then doing calculations that change them is not something the compiler will let you get away with either.
Steve
Or perhaps it's because "const int Erro(i);" is meaningless. What did you think that would do?
As I recently learned, that is a valid but rarely used C++ construction that defines a variable named Erro and initializes it, in this case to zero (since i=0). Obviously, a variable cannot be used as a function, as the statement in question suggests.
http://www.cplusplus.com/doc/tutorial/variables/
The OP appears to be computing a numerical derivative from data in an array.
Here is your sketch with the minimal changes to make it compile without errors or warnings. Since you have 'i' set to 0 and you never change it, the 'while' loop will compute the same values forever. Since you only calculate Erro[0] then your use of Erro[i + 1] is a bit of a problem.
int i = 0;
const int ldrPin0 = A0;
const int ldrPin1 = A1;
int Erro[2];
int dErro[1];
void setup()
{
Serial.begin(9600);
pinMode(ldrPin0 , INPUT);
pinMode(ldrPin1 , INPUT);
}
void loop()
{
while (i >= 0)
{
Erro[i] = analogRead(ldrPin0) - analogRead(ldrPin1);
dErro[i] = Erro[i + 1] - Erro[i];
}
Serial.println(Erro[0]);
Serial.println(dErro[0]);
}