void setup() {
// put your setup code here, to run once:
int i;
pinMode(11,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
while (i!=0){
digitalWrite(11,i);
i++
}
}
void setup() {
// put your setup code here, to run once:
int i;
pinMode(11,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
while (i!=0){
digitalWrite(11,i);
i++
}
}
i
was declared in setup(). When setup() is done i
is destroyed. Thus i
was not declared in the scope of loop().
Code tags, please use them?
Thanks. I forgot about code tags I'll use them from now on .
Thanks again.
Ok, but start now by editing your first post (the "pencil" button), select the code and press the "code" tag button ("</>"), then save. Thanks.
When you get an error that tells you “not declared in scope” you need to study scope and what it means. In brief and simplified:
You can declare things globally or locally.
Globally: normally at the beginning of the code outside any function ie not within any {}
Locally: inside a function ie between {}
The global variable will be visible everywhere in your code which can be handy but it also makes it vulnerable to change in a big complex code as all the code has access to it,
A local variables is created when the function runs and disappears when it completes so it can only be used within the function {}. This protects the variable from the rest of the code and is part of a concept called encapsulation
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.