Deriving an Alpha Character from its Ascii Decimal Value.

Objective : I want to use the Character "A" as part of a variable, lets say "A123".

The variable will be stored in and read from EEPROM.

From the ASCII tables "A" has a numeric values of 65.

The part I am having difficulty with is converting the stored value (65) to the character it represents (A).

Here is a simplified piece of code :

int ascii_A = 65;
char alpha_A[2];

void setup() {
    Serial.begin(9600);
    Serial.println("Serial Started!");

    Serial.println(ascii_A); //65
    Serial.println(ascii_A, DEC); //65
    Serial.println(ascii_A, HEX); //41
//    Serial.println(ascii_A, CHR); //?

    
//    alpha_A = (ascii_A, CHR);
//    Serial.println(alpha_A);
}

void loop() {

}

How can I print out the letter "A"?

Just use

  Serial.write(ascii_A);
  Serial.println("");

There is no conversion. There is formatting for output but it's never really converted, since the Arduino (and most computers) can't store "A" but they can store binary numbers.

char ascii_A = 'A';
void setup() {
  Serial.begin(9600);
  while(!Serial); //for Leonardo, Micro or Teensy
  Serial.print(ascii_A); //prints 'A'
  Serial.println();
  Serial.print((int)ascii_A); //prints '65'
}
void loop() {
  // do nothing
}

@Wandall : Thanks works great! - I see I should be using Serial.write() and not Serial.print().

@MorganS : As specified, I am storing the mixed alpha/numeric variable in EEPROM. I thought I know I cannot store a char.

Delta_G:
Why int in the first place? Why not store the number in a char and you won't need any conversions at all?

Because I am using EEPROM for storage which only allows 0 to 255.

A follow-on question...
Is there a smarter way to achieve the following conversion rather than with 26 lines of ifs?

byte controller[] = {65,1,2,3};
char series[2];

void setup()
{
  if (controller[0] == 65) series[0] = 'A';
  if (controller[0] == 66) series[0] = 'B';
  if (controller[0] == 67) series[0] = 'C';
  ...
  if (controller[0] == 88) series[0] = 'X';
  if (controller[0] == 89) series[0] = 'Y';
  if (controller[0] == 90) series[0] = 'Z';
}
void loop()
{
}

65 is 'A'.
A simple assignment is sufficient.

If you only want to assign capital letters, you can either use a simple range check ( x >= 'A' && x<= 'Z') or use isupper() and isalpha().

Groove:
65 is 'A'.

Or, more generally: to a computer (and for this, your Arduino counts as a computer), everything is a number.
Letters are numbers. Colors are numbers (or sets of numbers). All information takes the form of numbers.

Tools like the Arduino IDE allow you to pretend otherwise. They allow you to write things like digitalWrite(ledPin, HIGH); or Serial.println("Hello world!"); which then get translated into the appropriate sequence of numbers for your Arduino to process. The "text" which appears on your serial monitor is really just a sequence of numbers which, for your convenience, is displayed using shapes which you recognize as letters. (The letter shapes, too, are stored as numbers, in a font file in your PC. But I'm not going down that rabbit hole.)

And while we're on the subject of letters and numbers:

char series[2];  // you've declared series as an array

series = 'A';    // don't do this
series[0] = 'A'; // try this instead

series[1] = 0;   // it's a good idea to null-terminate your character arrays

odometer:
Or, more generally: to a computer (and for this, your Arduino counts as a computer), everything is a number.

You are not telling me anything I ALREADY know.
You are not addressing my actual question.

series[0] = 'A'; // try this instead

My mistake - pseudo code was typed directly into message and untested.

series[1] = 0;   // it's a good idea to null-terminate your character arrays

I think u mean

series[1] = '\0';

Maybe I just have to use a switch.. any shortcut ideas?

Why do you need a switch?
If all you need is to ensure that what you assign is an uppercase alphabetic, I already gave you two solutions.

I think u mean

Did you try it?

(sp. "you")

aisc:

series[1] = 0;   // it's a good idea to null-terminate your character arrays

I think u mean

series[1] = '\0';

Why do you think it makes any difference?
(It doesn't.)

Groove:
Why do you need a switch?
If all you need is to ensure that what you assign is an uppercase alphabetic, I already gave you two solutions.

Sorry but I cannot see how what u gave lets me achieve my objective.
Could you a clearer example?

if (controller[0] == 'X') series[0] = 'X';

aarg:
if (controller[0] == 'X') series[0] = 'X';

I already have that. In fact I turned it into a switch, but I am looking for a smarter shortcut.

switch(prefix){
    case 65 :   series[0] = 'A';
    break;
    case 66 :   series[0] = 'B';
    break;
    case 67 :   series[0] = 'C';
    break;
    case 68 :   series[0] = 'D';
    break;
    case 69 :   series[0] = 'E';
    break;
    case 70 :   series[0] = 'F';
    break;
    case 71 :   series[0] = 'G';
    break;
    case 72 :   series[0] = 'H';
    break;
    case 73 :   series[0] = 'I';
    break;
    case 74 :   series[0] = 'J';
    break;
    case 75 :   series[0] = 'K';
    break;
    case 76 :   series[0] = 'L';
    break;
    case 77 :   series[0] = 'M';
    break;
    case 78 :   series[0] = 'N';
    break;
    case 79 :   series[0] = 'O';
    break;
    case 80 :   series[0] = 'P';
    break;
    case 81 :   series[0] = 'Q';
    break;
    case 82 :   series[0] = 'R';
    break;
    case 83 :   series[0] = 'S';
    break;
    case 84 :   series[0] = 'T';
    break;
    case 85 :   series[0] = 'U';
    break;
    case 86 :   series[0] = 'V';
    break;
    case 87 :   series[0] = 'W';
    break;
    case 88 :   series[0] = 'X';
    break;
    case 89 :   series[0] = 'Y';
    break;
    case 90 :   series[0] = 'Z';
    break;
    default : 
    break;
}
  if (prefix >= 'A' && prefix <= 'Z') {
    series[0] = prefix;
  }

Whandall:

  if (prefix >= 'A' && prefix <= 'Z') {

series[0] = prefix;
  }

Ok that works - Thanks.

@Groove: I know you gave the same solution earlier, I just did not (and still don't) understand HOW it works, but it does give me the result I am looking for - thanks.

aisc:
Sorry but I cannot see how what u gave lets me achieve my objective.
Could you a clearer example?

It isn't entirely clear to me what your objective is, but my example pretty much covered what Whandall posted.
I think there's either some serious over-thinking or some under-thinking going on here

The letter A inside single quotes is a "character constant". That means that it is the programmer's representation of whatever number encodes the letter A. You actually don't need to know if this is 65 or 41 or 01000001. So if you are looking for some input to be an uppercase letter, you don't need to know if it's a particular number which is hard to remember, you only need to know that it falls somewhere between 'A' and 'Z'.

There are some useful tricks you can do with this. For example, if you have a single digit input and you need to convert this to an actual number instead of the ASCII code, you can do a simple subtraction:

int convertADigit(char digit) {
  //convert a single digit to an integer - return negative one if it's not a digit.
  if(digit >= '0' && digit <= '9') {
    return digit - '0'; //convert ASCII code to an integer
  } else {
    return -1; //not a digit
  }
}

I have no idea what the ASCII code for '0' is without looking it up but I don't need to: the compiler knows.

Whandall:

  if (prefix >= 'A' && prefix <= 'Z') {

series[0] = prefix;
  }

if (isupper(prefix)) series[0] = prefix;

Groove:
It isn't entirely clear to me what your objective is, but my example pretty much covered what Whandall posted.
I think there's either some serious over-thinking or some under-thinking going on here

Why so grumpy?
You have been both acknowledged and thanked.
Although you offered a solution, given your example, I was not familiar enough with it to use it.
Whandall's example put it into a context that I could see how it applied to my code.

aarg:

if (isupper(prefix)) series[0] = prefix;

Thanks aarg, I am presently using this :

if (prefix >= 'A' && prefix <= 'Z') series[0] = prefix;

But I can see how your example is a "smarter" version, so will change my code.