A little confusion about pin numbers

The referance pages state the following,

Pin mapping
The Arduino pin numbers corresponding to the analog pins are 14 through 19. Note that these are Arduino pin numbers, and do not correspond to the physical pin numbers on the Atmega168 chip. The analog pins can be used identically to the digital pins, so for example, to set analog pin 0 to an output, and to set it HIGH, the code would look like this:

pinMode(14, OUTPUT);
digitalWrite(14, HIGH);

But in one of the working examples, it shows,

int potPin = 2; // select the input pin for the potentiometer

Which is the pin number on the Proto Shield (0-5) but according the info above, that should be,
int potPin = 16;

I know these aren't the physical pin numbers, but are they supposed to be 14 to 19, or 0 to 5? If the later, how does it discern the difference between Digital pin 2 and Analog pin 2?

Or did I compleatly miss something here?

The confusion is because the Arduino numbers analog pins differently from digital pins.

When using analog functions, the pins are numbered 0-5. but these same pins are numbered 14-19 when used with digital functions.

The arduino software knows that digital pin 2 is a different physical pin from analog pin 2 (and that analog pin 2 is the same physical pin as digital pin 16)

A diagram showing the analog and digital pin numbers for the analog ports would help. If you can't find a diagram that shows this, draw it out for when you need to wire things up.

2 Likes

When using analog functions, the pins are numbered 0-5. but these same pins are numbered 14-19 when used with digital functions.

That explains it, thanks