I try to learn how to program my arduino from the learning section on this site, but i find it a bit confusing.
I'll give an example :
The example code for Setup. I expected to find all the code within setup() but some of the code is outside.
Why is that ?
because of this i still fail to understand the very basic structure of the IDE, can someone point me to a better place to learn arduino code ?
int buttonPin = 3;
void setup()
{
 Serial.begin(9600);
 pinMode(buttonPin, INPUT);
}
void loop()
{
 // ...
}
buttonPin is a variable declared outside of the setup() function so that it can be used in the loop() function, or any other functions. It's called a global variable, because it is accessible from anywhere in the code.
If you declared it like so:
void setup()
{
 int buttonPin = 3;
 Serial.begin(9600);
 pinMode(buttonPin, INPUT);
}
Then it wouldn't be accessible outside setup(). It is then called a local variable, and its scope is limited to within setup()