How to set pin mode if you have both analog and digital inputs & outputs

Hey guys,
I would like to know how I can set pin mode if I have both analog and digital pins. For example:

int tempPin = 2; // which is analog pin 2
int redPin = 2; // which is digital pin 2
int greenPin = 3; // which is digital pin 3

void setup()
{
pinMode(tempPin, INPUT);
pinMode(redPin , OUTPUT);
pinMode(greenPin , OUTPUT);
}

The problem is, since tempPin is analog pin 2 and also redPin is digital pin 2. Will arduino itself know which is analog pin 2 and digital pin 2. Or is there a way to set pin mode.

Thanks.

You only need to set the pinMode for a Analog pin when you want to use it as a Digital I/O.

If you want to use it as a Digital I/O use the aliases "A0, A1, A2..". The compiler will convert those to the correct pin numbers, e.g. 14, 15, 16 on the Uno.

Can you give me an example on how to set Analog pin as a digital i/o pin.

So, can I write the code as:

int tempPin = 2; // which is analog pin 2
int redPin = 2; // which is digital pin 2
int greenPin = 3; // which is digital pin 3

void setup()
{
pinMode(A2, INPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
}

Can you give me an example on how to set Analog pin as a digital i/o pin.

For output on A0 use

pinMode(14, OUTPUT);

or

pinMode(A0, OUTPUT);

For digital input on A1 use:-

pinMode(15, INPUT);

or

pinMode(A1, INPUT);