Pages: [1]   Go Down
Author Topic: error: 'Target' was not declared in this scope  (Read 785 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 2
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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);

}
Logged

Norway@Oslo
Offline Offline
Edison Member
*
Karma: 12
Posts: 2033
loveArduino(true);
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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);

}
Logged

UK
Offline Offline
Faraday Member
**
Karma: 17
Posts: 2884
Gorm deficient
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
int MOVE (Target) {
You haven't given "Target" a type.

Best if you post the whole sketch.

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

why not just simply:
Code:
digitalWrite(UP_DOWN, LOW);
?
« Last Edit: April 07, 2010, 06:30:26 am by GrooveFlotilla » Logged

Per Arduino ad Astra

0
Offline Offline
Newbie
*
Karma: 0
Posts: 2
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Pages: [1]   Go Up
Jump to: