Pin A5 vs pin 5 on Mega2560

When using Pins A5 and pin 5 on Mega2560, do I actually refer to them as, for example:

const int Bell_Input = 5;

const int Light_Input = A5;

Or does A5 have a different number reference to be used?

Thanks,

Sid

If you look closely at your Arduino board, you often find a marking that groups some of the pins together. One of those is likely marked "Analog". The 5th pin in that set is capable of being used as an analog pin, A5. The symbolic constant, "A5", simply makes it easier to identify the function of the pin in your code.

A5 I think can also be referenced as 59. (A0 = 54, A1 =55, etc.) You can check in pins_arduino.h for the Mega and confirm the analog to digital mapping.

So, am I correct in saying this statement will work "as is":

const int Light_Input = A5;

Thanks,

Sid

Yes. Using the symbolic constants (A0, A1 etc) means that the program can be compiled for other boards without having to know what the actual pin numbers are.

One confusion can be that with the analogRead() function the analogue pins can be referred to simply as numbers so that

analogRead(5);

reads the analogue value from analogue pin 5 rather than digital pin 5 (which is impossible anyway). It is, however, equally valid to use

analogRead(A5);

which also makes the meaning clearer in my opinion.

Great, very understandable.

Thanks again for your help. You have all the answers.

Sid

You have all the answers.

Whilst it is nice of you to say so, it is certainly not true !