Analog In / PWM

1) What difference does it make between reading inputs through a PWM pin or Analog In pin?

2) How do I indicate Analog In pins? Meaning: do I use "int x = 0;" or "int x = A0;" ??

PWM pins are digital pins, so reading a PWM pin will only give you a HIGH or LOW result. The Analogue input pins are connected to the onboard AD converter, so will give a result that reflects the voltage applied to the pin.

If you want to use an Analogue input pin as a digital pin, then you can use the A0 naming.

What difference does it make between reading inputs through a PWM pin or Analog In pin?

PWM is a function of otherwise digital pins. They can not read a varying voltage.

How do I indicate Analog In pins? Meaning: do I use "int x = 0;" or "int x = A0;" ??

A0 is an alias meant to define the analog pin when used as a digital pin. 0 is the correct value for the first analog pin.

A0 will work, but that is not what is was meant to be used for.

1) I thought you can read a varying potentiometer voltage on a PWM pin which means it can read a varying voltage?

2) Let's say I want to use a the Analog In Pin 3. If I'd write:

int xPin = 3;

it'll interpret it as a digital / PWM pin 3. If I'd write: int xPin = A3; does that clarify it? Should I do that instead??

1) No, PWM is output, not input. You can only read varying voltages on the analogue pins.

2) If you did analogRead(3), it would refer to analogue pin 3. If you did digitalRead(A3), it would also refer to analog pin 3, but as a digital input, not connected to the ADC.

Here's something else you might find useful:

If you use the analog pins 0 thru 5 as digital inputs or outputs, you can simply continue on from pin 13 and call them pins 14 thru 19. This comes in handy if you want to initialize or access a lot of pins with an array - just use the array index for the pin number.

Correct. And A3 is simply defined as

static const uint8_t A3 = 17;

assuming you have an Uno, or other 328 based Arduino.

Lets make the confusion complete ;) it does not matter if you call analogRead(A3) or analogRead(3) or analogRead(17) - they all go to the same pin. (There is code in the core to cope with analog pins having "three names" - thus helping the newcommer to get stuff working)

On the digitalRead there is not much choice. It is only the number - 13. Any alias/constants you do on your own.


Meanwhile, back to the original question and confusion of the thread.

You can set "any" pin with pinMode to input or output. "Any" is in quotes as restrictions apply.(Usually you stay away from pin 0 and 1 as they are used by Serial) You can do digitalRead, analogRead, digitalWrite, analogWrite on "any" pin. ... and there are restrictions - analogWrite will only work on the pins marked with "PWM"; analogRead will only work on analog pins.