2

I often see code like this:

const int piezo = A0;
const int sensorPin = A1;

From my understanding, an int variable can hold things like -123, 0, 1, 456, etc.

How can A0 or A1 be an int?

2

The board definition (pins_arduino.h) has this:

static const uint8_t A0 = 14;
static const uint8_t A1 = 15;
static const uint8_t A2 = 16;
static const uint8_t A3 = 17;
static const uint8_t A4 = 18;
static const uint8_t A5 = 19;
static const uint8_t A6 = 20;
static const uint8_t A7 = 21;

Since A0 is a constant variable equal to 14, if you assign that to a variable, it just assigns 14.

In other words:

A = 14.
B = A.
Therefore B = 14.
1

They are defined in the Arduino libraries, and the Arduino libraries will translate them into the appropriate pins and registers before they are used. But in the meantime they're numbers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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