Quick win: Analog pullup (digital write high)

Hi all

Trying to figure out why

digitalWrite(14 + MyAnalogPin, HIGH);

makes my project work...

but digitalWrite(MyAnalogPin, HIGH);

does not?

THANKS

Because when analogue pins are used as digital inputs or outputs that is how they map.
Analogue pin 0 is digital pin 14 and so on.
You need this because if you just use the analogue pin number you would have two pins being referred to as pin 0

you could also do

int val = analogRead(14); works only on UNO/328

as

(from Wprogram.h)
const static uint8_t A0 = 14;
const static uint8_t A1 = 15;
const static uint8_t A2 = 16;
const static uint8_t A3 = 17;
const static uint8_t A4 = 18;
const static uint8_t A5 = 19;
const static uint8_t A6 = 20;
const static uint8_t A7 = 21; // internal temp ? sensor of a 328

What does "MyAnalogPin" contain?

It looks like you are doing this...

int MyAnalogPin = 0;

...when you should to this:

int MyAnalogPin = A0;

By using A0 (or A1 etc.) it will automatically add 14, or whatever is needed on the chip you are using. (I've head megas use a larger number.)