I would like to take the ASCII number and convert it to the actual character as shown in the following example program. Is there a function that will do this?
void setup(){
Serial.begin(9600);
}
void loop()
{
String strArray[200];
if (Serial.available()>0)
{
int i = 0;
while(Serial.available() > 0)
{
strArray[i] = Serial.read();
Serial.print("Array number ");
Serial.print(i);
Serial.print(" is ");
Serial.print(strArray[i]);
Serial.print(" which is the ASCII # for the character ");
Serial.println(strArray[i]); // <== how can the # be converted into the character
i++;
}
strArray[i] = '\0';
}
}
I would like to take the ASCII number and convert it to the actual character as shown in the following example program. Is there a function that will do this?
I recognize all the words in this sentence, and I even know what they all mean. Arranged in this order, though, there is little meaning.
An ASCII value is a position in a table. That position corresponds to a letter. Take the value 0x50 for instance. The character at that position in the ASCII table is 'P'. If you Serial.print(0x50), it will print the letter 'P'. If you set a char variable to 0x50, like so:
Thank you Rob and Paul. Your advice is greatly appreciated.
I was looking to test the first character in the string sent serially to the Arduino. The following code works well (thank you again). I placed a copy of the relevant section below for anyone searching for a solution to a similar issue.
void setup(){
Serial.begin(9600);
}
void loop()
{
char charArray[200];
if (Serial.available()>0)
{
int i = 0;
String commandString = "";
while(Serial.available() > 0)
{
charArray[i] = Serial.read();
delay(10);
commandString = commandString + (charArray[i]);
i++;
}
charArray[i] = '\0';
if (charArray[0] == 60) // test if the first character in string is "<"
{
// if the character "<" starts the string - do some work.
}
}