Variables

Hello guys, I have a question with the topic variables.

so, variable is a place where u can store a data.

so when you make a variable with dataype int (int ledpin=13;) then u store a value 10 in a variable named ledpin.

BUT how can arduino know its a pin number 13 form arduino or a random number 13 that we are storing there.

int ledpin=13; //stores a 13, not a 10 to that variable :wink:

As far as Arduino is concerned, that's just a number, specifically 13 being stored in that variable.

When you call digitalWrite(), the first argument is a number (actually, so is the second - HIGH and LOW are just #defined as 1 and 0 respectively).
in digitalWrite() and the related functions, Arduino looks up what pin that number corresponds to. The defines like D0~D13 are just #defined as 0~13, likewise A0~A5 are #defined as 14~19. (analogRead() will take either the 14~19 values, or 0~5 - it's smart enough to figure out which you've given it).

These are all just numbers - it's what you do with them that gives them meaning :wink:
Hell, you can even do stuff like pinMode(13,1); (INPUT, OUTPUT, INPUT_PULLUP are defines - I forget which is which) - though you shouldn't, as that just makes your code harder to read.

The context in which you use it is important
pinMode (ledPin, OUTPUT);for example