1

Can analog pins be defined by their digital pin number, and be used for analog purposes?

For example, instead of defining A0 for a pinout with the Uno, it could be 14?

Where is this documented? Is there a PDF type manual related to this, but not so low level to get into the ATmega chip?

enter image description here

https://www.arduino.cc/en/Hacking/PinMapping2560

1 Answer 1

4

For example, instead of defining A0 for a pinout with the Uno, it could be 14?

Yes. In fact A0 is just a placeholder for the number 14.

For all these things you should look in the pins_arduino.h file (Arduino\variants\wifio) for any variant you are interested in. That's where most of these symbols are defined. For example:

#define PIN_A0   (14)                                                                                   
#define PIN_A1   (15)                                                                                   
#define PIN_A2   (16)                                                                                   
#define PIN_A3   (17)                                                                                   
#define PIN_A4   (18)                                                                                   
#define PIN_A5   (19)                                                                                   
#define PIN_A6   (20)
#define PIN_A7   (21)

static const uint8_t A0 = PIN_A0;
static const uint8_t A1 = PIN_A1;
static const uint8_t A2 = PIN_A2;
static const uint8_t A3 = PIN_A3;
static const uint8_t A4 = PIN_A4;
static const uint8_t A5 = PIN_A5;
static const uint8_t A6 = PIN_A6;
static const uint8_t A7 = PIN_A7;

Incidentally, on the Uno you can also just use 0 for A0 with analogRead().

2
  • 3
    You can use 0 for A0 only in analogRead. If you are using it as a digital pin you still have to either call it 14 or A0.
    – Delta_G
    Aug 4, 2020 at 23:56
  • @Delta_G Good point on the usage distinction.
    – Majenko
    Aug 5, 2020 at 10:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.