Saving Analog Pin Name in variable

Hi,

i am currently working on a project and because things got a bit more complicated than planned, I need to define my Pin Layout as a variable on the top of the code (as you usually do). Now I have the problem that I dont know which variable type to choose, because I want to be able to save A0 or A1 and read that out with serial.println. Int doesnt work, because it cant store the A. Do you understand my Problem? Any Idea?

Thank You very much!

byte analogPin = A0;

works for me

byte analogPin = A0;

...
...

Serial.print (F("input pin is A"));
Serial.println ((int) (analogPin - A0));

The analog pins can also be referred to by pin numbers. A0 is pin 14, A1 is pin 15, ... Pin numbers can be byte data type as there is no Arduino with more than 255 pins. I use const byte as the pin numbers, once assigned, will not change.

const byte anaologIn = A0;
// or
const byte analogIn = 14;

How many pins does your Arduino have? Use the smallest type that can accommodate that number of pins.

If the pin number can not change at run time (and it would be VERY unusual if they could), make the variable const.

AWOL:

byte analogPin = A0;

works for me

byte analogPin = A0;

...
...

Serial.print (F("input pin is A"));
Serial.println ((int) (analogPin - A0));

Thank you very much for your answer!

Storing the Pin in a Byte works perfectly. But if I want to read it out by Serial.println(Pin_Number); it will only show the Numbers, for example out of A0 it makes a 14. I want to be able to read them out for error-finding. Any Ideas?

Any Ideas?

I just posted an example of how to do that.

Ah. Now i got it. Thank you. (Sorry, I am still kind of a beginner in Arduino.)

To make it a little more general:

byte inputPin = A0;

This should correctly display almost all analog/digital pin names/numbers:

  if (inputPin < A0)
    Serial.print((int)inputPin);  // Digital pins (0-13 on UNO)
  else
  {
    // Analog Input Pins (14-
    Serial.print('A');
    Serial.print((int) (inputPin - A0));
  }