Pin number of analog pins

Are A0, A1… integers or some other data type?

void myfunction(int pin) ;

myFunction(A0); ← doesn’t work
myFunction((int)A0); ← doesn’t work

It might depend on which board you're compiling for but most likely they're uint8_t (AKA "byte"). This is their definition for Uno, Nano, Pro Mini:

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;

What do you mean by "doesn't work"?

Hello rhj4

rhj4:
void myfunction(int pin) ;

myFunction(A0); ← doesn’t work
myFunction((int)A0); ← doesn’t work

That should work; byte too.
But “myfunction” isn’t “myFunction” (see the F).
Please post ALL your code by copy and paste.

Regards,
bidouilleelec

rhj4:
Are A0, A1… integers or some other data type?

void myfunction(int pin) ;

myFunction(A0); ← doesn’t work
myFunction((int)A0); ← doesn’t work

Doesn’t work is such a useless statement :wink: Does it compile (or not)? As it stands now (see @bidouilleelec’s comment on case sensitivity), probably not. If it compiles what does it do and what do you expect it to do?

rhj4:
Are A0, A1… integers or some other data type?

void myfunction(int pin) ;

myFunction(A0); ← doesn’t work
myFunction((int)A0); ← doesn’t work

If you grep the sources you can answer questions like this for yourself, its an open source platform so you
already have all the code of the Arduino runtime on your machine in human readable form.

It matters which Arduino board you are talking about, some allow digital operations on analog pins,
some allow this on some analog pins, some may not. Uno and Mega and Pro Mini and Nano all allow it
except for A6 and A7 if they are brought out on an ATmega328 board (hardware restriction).

So if myFunction is doing standard pin operations, digital or analog, it should be fine for these.

Also to note some of the knock-off boards I've used will not allow you to use the digital numbers for the analog pins. A0-A5 have to be used even though they act as digital outputs/inputs etc.

Try

Serial.println(A0);

...R

PilotinControl:
Also to note some of the knock-off boards I've used will not allow you to use the digital numbers for the analog pins. A0-A5 have to be used even though they act as digital outputs/inputs etc.

BS. The knockoffs use the same chip and have NO idea about the compiler. The Ax variables ARE those numbers...

#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;

Although I think it is wayyyyy cleaner to just use A0, A1 etc names instead 14, 15 etc

PilotinControl:
Also to note some of the knock-off boards I’ve used will not allow you to use the digital numbers for the analog pins. A0-A5 have to be used even though they act as digital outputs/inputs etc.

What core were you using? It’s not a property of the board. It’s the libraries that determine whether A0 = 14 or what.

I would expect that something might be wrong where you had to use numbers and couldn’t use the A-notation if the A-notation wasn’t defined. But I can’t imagine what would cause the numbers to not work if symbols given the same numeric values would work.