Hello all,
I'm a bit confused about the nomenclature with regard to analog pins
so I've read the Arduino literature that states that analog pins are referenced using A0 A1 ect.
but it seems like to use the analogRead function you must simply use the pin number (0, 1, 2, ect.)
so my question is can you use the A0 reference in any function? or maybe a more precise question and really what I would like to know
How do I read from my analog pins? an example code would be much appreciated.
so I've read the Arduino literature that states that analog pins are referenced using A0 A1 ect.
Analog pins can be used as digital pins, too.
When used as an analog pin, the first one is referred to by the number 0. When the first analog pin is used as a digital pin, it is referred to by the name A0.
While the name A0 can be used when the pin is being used as an analog pin, and analogRead() will figure out that you meant the value 0 (not the value 14 or 54), I don't like people that do that.
I prefer that people do use the A0 type of notation here since there is another pin 0 on the board. I like for the pin number to be same no matter how I use it. I don't want to have to think about context to figure out if it means analog 0 or digital 0. And that goes triple if we are talking about putting it in a variable where the context of which function is using it may not be immediately apparent.
I prefer that people do use the A0 type of notation here
I am with you on that. It does no harm, explicitly states which pin is being used using the pin name used on the Arduino board and prevents confusion between digital pin 0 and analogue pin 0 etc.
great thanks everyone, makes more sense to me to use the A0 as it creates less contextual confusion. That being said all the sketches I've looked at don't use A0 (granted I've only seen a few). Anyways thanks again.
To read A0, you can do analogRead(0), analogRead(A0), or analogRead(14). (A0 is just #defined as 14 - the first number after the number of the last "digital pin". analogRead() subtracts 14 from the value you pass in if it's too high to be an adc channel number)
For official boards, the A# notation is best practice.