Go Down

Topic: error: 'Target' was not declared in this scope (Read 948 times) previous topic - next topic

Peter S

error: 'Target' was not declared in this scopeBad error line: -2

When I try and compile my code, This the error message a get.

It doesn't highlight anything. But is says theirs an error with a negative line number, if you insert new lines at the top of the code you just get this error message "error: 'Target' was not declared in this scope"

I think the Error message is saying that my variable 'Target' need to be declared somewhere else in the program but it is only used in 1 function (see below).  If I take out the second line ('int Target;') you get the same error message. I also copied the function into its own sketch and I get the same error message.

Can anybody Help me ???


int MOVE (Target) {
 int Target;
 if (Target < analogRead(Gear_Position)){
   digitalWrite(UP_DOWN, LOW);
 }
 else {
   digitalWrite(UP_DOWN, LOW);
 }
 while (Target != analogRead(Gear_Position)){
   analogWrite(Motor_Control, SPEED);
   CHANGING_LED();
 }
 
 analogWrite(Motor_Control, 0);

}

AlphaBeta

int MOVE(int Target) {
if (Target < analogRead(Gear_Position)){
  digitalWrite(UP_DOWN, LOW);
}
else {
  digitalWrite(UP_DOWN, LOW);
}
while (Target != analogRead(Gear_Position)){
  analogWrite(Motor_Control, SPEED);
  CHANGING_LED();
}
 
analogWrite(Motor_Control, 0);

}

Groove

#2
Apr 07, 2010, 01:28 pm Last Edit: Apr 07, 2010, 01:30 pm by GrooveFlotilla Reason: 1
Code: [Select]
int MOVE (Target) {

You haven't given "Target" a type.

Best if you post the whole sketch.

Code: [Select]
if (Target < analogRead(Gear_Position)){
  digitalWrite(UP_DOWN, LOW);
}
else {
  digitalWrite(UP_DOWN, LOW);
}


why not just simply:
Code: [Select]
digitalWrite(UP_DOWN, LOW);?
Per Arduino ad Astra

Peter S

Thanks, putting int' in front of the 'Target' Parameter work.

I'd forgotten to change the LOW to an HIGH after I copy the line, thanks for saving me some debugging time.

if (Target < analogRead(Gear_Position)){
  digitalWrite(UP_DOWN, HIGH);
}
else {
  digitalWrite(UP_DOWN, LOW);
}

Peter

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy