Hi,
I have a sensor and I receive values from it between 0 and 255. I need to convert the readings from the sensor to an array of char.
For example, if my sensor reads 97 I need this 97 reading converted to the "a" (which is the representation of 97 in the ASCII table).
I need something like:
char temp[] = convertToASCII(97);
Which would be the same as:
chart temp[] = "a";
I read a lot in Google but could not find a way to do that.
Thank you.
int x = 97;
char y = x;
It's just numbers. There is no "conversion" needed.
Regards,
Ray L.
char string_to_send[2];
int i = 97;
string_to_send[0] = i;
string_to_send[1] = '\0'; nul to terminate the string.
I think that, any time you are trying to shove 2 bytes of information (i.e., an int) into a 1 byte bucket (i.e., a char), you should explicitly cast the assignment. It helps document what you're doing:
void setup() {
// put your setup code here, to run once:
char myStr[20];
myStr[0] = (char) 97; // Use a cast
}
Your code didn't work because you didn't define the myStr[] array.