#define trigPin 7
#define echoPin 6
int tank = 0;
int phase = 0;
void setup() {
// put your setup code here, to run once:
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(9, OUTPUT);
pinMode(8, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(2, INPUT);
analogWrite(11, 240);
analogWrite(10, 255);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);
digitalWrite(13, HIGH);
digitalWrite(12, LOW);
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
if (target() > 15)
{
follow();
}
else
{
AO();
}
void loop() {
// put your main code here, to run repeatedly:
if (target() > 15)
{
follow();
}
else
{
digitalWrite(13, LOW);
digitalWrite(12, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
delay(3000);
digitalWrite(13, HIGH);
digitalWrite(12, LOW);
digitalWrite(9, HIGH);
digitalWrite(8, LOW);
}
}
functions 1
int target()
{
long duration = 0;
long distance = 0;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration * 0.0343) / 2;
return distance;
}
Arduino: 1.8.12 (Windows Store 1.8.33.0) (Windows 10), Board: "Arduino Uno"
C:\Users\Dorian\Documents\Arduino\SECRET_EXPERIMENT\SECRET_EXPERIMENT.ino: In function 'void setup()':
SECRET_EXPERIMENT:26:7: error: 'target' was not declared in this scope
if (target() > 15)
^~~~~~
SECRET_EXPERIMENT:28:5: error: 'follow' was not declared in this scope
follow();
^~~~~~
C:\Users\Dorian\Documents\Arduino\SECRET_EXPERIMENT\SECRET_EXPERIMENT.ino:28:5: note: suggested alternative: 'malloc'
follow();
^~~~~~
malloc
SECRET_EXPERIMENT:32:5: error: 'AO' was not declared in this scope
AO();
^~
C:\Users\Dorian\Documents\Arduino\SECRET_EXPERIMENT\SECRET_EXPERIMENT.ino:32:5: note: suggested alternative: 'A7'
AO();
^~
A7
SECRET_EXPERIMENT:35:15: error: a function-definition is not allowed here before '{' token
void loop() {
^
AO:2:1: error: a function-definition is not allowed here before '{' token
{
^
LF:2:1: error: a function-definition is not allowed here before '{' token
{
^
MP:3:1: error: a function-definition is not allowed here before '{' token
{
^
ST:4:1: error: a function-definition is not allowed here before '{' token
{
^
TS:2:1: error: a function-definition is not allowed here before '{' token
{
^
TS:17:1: error: expected '}' at end of input
}
^
exit status 1
'target' was not declared in this scope
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
can someone translate what the error is and what it means and how i can fix it.
A very helpful troubleshooting tool is the Auto Format feature (Tools > Auto Format in the Arduino IDE or Ctrl + B in the Arduino Web Editor). If you do an Auto Format and then compare the resulting indentation to your intended program structure, it will quickly point you to where there is a missing or extra brace, which is the cause of your error.
Another useful feature of the Arduino IDE/Arduino Web Editor is that when you place the cursor next to one bracket, it puts a box around the matching bracket. In the Arduino IDE, if the cursor is next to the closing bracket and the opening bracket is off the screen then it will show the opening bracket line in a tool tip after a short delay.
You should be creating your functions before you try to call them and separate your error messages from your code. Your making function calls to functions that dont exist AO() AND follow()
notsolowki:
You should be creating your functions before you try to call them
That's not necessary. The Arduino development software automatically generates function prototypes for all functions in .ino files that don't already have manually added prototypes.
You are welcome to put the function definitions anywhere you like in the program. I prefer to place the definitions below the call location. This way, the high level code (setup() and loop()), which you would want to look at first, is at the top of the program.
Solowki i have the code details i am just not sharing the code with you guys.
i auto format the code and it still comes up with the error code of that target was not declared in this scope.
can someone please explain what is wrong with the code and tell me what to change so i can fix this problem.
“i have the code details i am just not sharing the code with you guys.”
What ?
Top secret ?
Some might say, back at you.
That's not the problem can someone please tell me whats wrong and what I can change. Anything else except the problem doesn't matter. just give me a brief explanation of what the problem wants me to do and how i can do it.
which problem just one or all 13?
How to fix the error message 'target' wasn't declared in this scope.
A mismatched bracket { } or () somewhere.
But as you do not want to show your full code, we cannot say where.
Auto format your code, as suggested, and then look for it yourself.
Oh that one. well the problem is that 'target' was not declared in that scope
yes that's what i meant, so please can you tell me what to do.
Each { needs a friend }
something like this maybe?
#define trigPin 7
#define echoPin 6
int tank = 0;
int phase = 0;
void setup() {
// put your setup code here, to run once:
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(9, OUTPUT);
pinMode(8, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(2, INPUT);
analogWrite(11, 240);
analogWrite(10, 255);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);
digitalWrite(13, HIGH);
digitalWrite(12, LOW);
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
if (target() > 15)
{
follow();
}
else
{
AO();
}
}
void loop() {
// put your main code here, to run repeatedly:
if (target() > 15) {
follow();
} else {
digitalWrite(13, LOW);
digitalWrite(12, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
delay(3000);
digitalWrite(13, HIGH);
digitalWrite(12, LOW);
digitalWrite(9, HIGH);
digitalWrite(8, LOW);
}
}
int target() {
long duration = 0;
long distance = 0;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration * 0.0343) / 2;
return distance;
}
arduinoproblems:
i auto format the code and it still comes up with the error code of that target was not declared in this scope.
That's expected. Auto format isn't going to fix your code. It is only going to make it easier for you to see the problem. Look very carefully at the indentation of your code. each function should start unindented. If you see a function that starts with an indent, then you know that you are missing a closing brace (}) above that.
You just need to take some time to study your code and understand the syntax. This is fundamental stuff that you need to learn in order to have any success with Arduino.
the problem was a missing bracket.
“ the problem was a missing bracket.”
That’s what we said many many times.
“ SECRET_EXPERIMENT”
Secrets always cause problems.