Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!
Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.
Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!
[Solved] Error: "[int variable] was not declared in this scope"
(@karol)
Eminent Member
Joined: 4 years ago
Posts: 12
Topic starter
March 1, 2021 12:19 AM
I defined variables in the void () setup section:
int PumpPin=13;
In the loop section:
digitalWrite(PumpPin,HIGH);
Compilation error: 'PumpPin' was not declared in this scope
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2859
March 1, 2021 5:50 AM
Hi Karol,
unfortunately, without the rest of the code, I cannot determine what the issue may be. Where in the code did you define PumpPin?
Since the declaration of PumpPin seems correct, it probably is a matter of scope - meaning: the variable is unknown in the loop.
This can happen when you declare the variable (for example) in another function, for example in setup().
If that is the case then the variable will not be known in "loop".
As an illustration, just in case you're not very familiar with the scope of variables;
int A=13;
void setup() {
int B=13;
...
}
void loop() {
int C=13;
...
}
Â
The variable "A" is defined outside of the functions, therefor know within the functions.
However, the variable "B" is only available in the "setup" function, whereas the variable "C" is only known in the "loop" function.
(@karol)
Eminent Member
Joined: 4 years ago
Posts: 12
Topic starter
March 1, 2021 10:52 PM
Great, thanks Hans, i will try.
And you also showed me how to write a post (the code in special format).
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2859
March 2, 2021 6:30 AM
You're welcome, and please let me know if it worked 😉Â