Page 1 of 1
Forum

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!




Error: "[int variab...
 
Share:
Notifications
Clear all

[Solved] Error: "[int variable] was not declared in this scope"

4 Posts
2 Users
0 Likes
3,542 Views
(@karol)
Eminent Member
Joined: 3 years ago
Posts: 12
Topic starter  

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


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2661
 

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.


   
ReplyQuote
(@karol)
Eminent Member
Joined: 3 years ago
Posts: 12
Topic starter  

Great, thanks Hans, i will try.

And you also showed me how to write a post (the code in special format).


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2661
 

You're welcome, and please let me know if it worked 😉 


   
ReplyQuote

Like what you see and you'd like to help out? 

The best way to help is of course by assisting others with their questions here in the forum, but you can also help us out in other ways:

- Do your shopping at Amazon, it will not cost you anything extra but may generate a small commission for us,
- send a cup of coffee through PayPal ($5, $10, $20, or custom amount),
- become a Patreon,
- donate BitCoin (BTC), or BitCoinCash (BCH).

Share: