Please assist:
How do we know the difference between initializing a pin and declaring a variable:
for eg:
Initializing a pin:
int led 13;
and declaring a variable:
int LED 13.
Both can mean the same thing...assigning the LED to pin 13, or it can mean assigning the value of 13 to the variable called LED.
You left out the = sign.
But they ARE the the same thing.
You assign the value 13 to a variable LED then you use that variable in a digitalRead() or digitalWrite().
And you can save some memory by using byte not int.
edit.... in other words, int led 13 does NOT initialise a pin, there's no such thing.
You don't know the difference from that; it depends on the context. You however can make your declarations a lot more self-explaining.
int pinLedRed = 11;
int pinLedGreen = 12;
int valueGreen = 33;
int valueRed = 345;
It's more typing but one can immediately see what is what.
Some people use const int LED = 13 (or byte) for the pin or [/i]#define LED 13[/i]; both don't take the above into account but make clear that it can not be changed and hence it must be the pin.
Also, there is a difference between:
#define LED 13 // Both of these should not appear in the same source file
int LED = 13;
A #define is a symbolic constant that results in a textual replacement in the source code. It does NOT create a variable that you can use, manipulate, or view in a debugger (if we really had one). No memory is allocated for a variable named LED in the compiled code.
The second statement is not a data declaration, it is a data definition because memory is allocated for LED. Data declarations, like the use of the extern keyword or function prototypes, do not allocate memory but are in the file simply to allow type checking by the compiler. Data definitions, on the other hand, do provide for type checking, but they also allocate memory for the variable.
In your example, two different variables, led and LED, are defined (assuming there was an equals operator) and are different variables. A convention that is fairly widely used is to put enums, #define's, and constants using upper-case letters.