I am working on a project where I want to send multiple values via bluethooth.
but now I'm having a problem, if I forward a character or a number, I get the numbers and characters in dec on the receiver.
now the question is, how do I change this back to characters and normal numbers?
as an example. if I send 49 I get 5257 on the receiver.
so when I send (, x49, y49) I get (441205257441215257).
how do I convert it back to chars. and big numbers.
so when I send (, x49, y49) I get (441205257441215257).
WHY would you print the values receivedwithoutanyspacesbetweenthem?
Doesn't that make it way more difficult to understand what you are getting?
Look at any ASCII table. 52 and '4' are the SAME value. If you assign 52 to a char variable and print it, you'll see a '4'. If you assign '4' to an int variable, and print it, you'll see 52.
It depends also on whether you send a char or a byte. 4 as a char is 52, as a byte it's 4. Print sends characters as it assumes the value to be interpreted as ASCII. Write sends bytes.
JazzJackRabbit:
if I forward a character or a number,
What you really want is far from clear. "Forwarding" a character is novel to the point of being unique. If you Serial.printed your values like most everybody else does, you might get a desired result.
Add 48 on the receiver side make a small function which will check if its in ascii number then change it adding 48. Note its only if you are sending numbers.
DKWatson:
It depends also on whether you send a char or a byte. 4 as a char is 52, as a byte it's 4. Print sends characters as it assumes the value to be interpreted as ASCII. Write sends bytes.
PaulS:
WHY would you print the values receivedwithoutanyspacesbetweenthem?
Doesn't that make it way more difficult to understand what you are getting?
Look at any ASCII table. 52 and '4' are the SAME value. If you assign 52 to a char variable and print it, you'll see a '4'. If you assign '4' to an int variable, and print it, you'll see 52.
So, therein lies a clue.
I've tried both, but with (Serial.print or Serial.write) I get the same on the receiver.
I let the receiver search for the comma, then he looks if it is x or y, then he fills in the next value at int.X or int.Y.
sorry for my orthography, but I'm from the Netherlands, I'll translate it via google translate.
Our replies to your post were a (failed) attempt to get you to POST YOUR CODE.
You are, apparently, storing what should be char data in int variables. Store the char data in char variables, and you WILL see a difference when you print the data.
PaulS:
Our replies to your post were a (failed) attempt to get you to POST YOUR CODE.
You are, apparently, storing what should be char data in int variables. Store the char data in char variables, and you WILL see a difference when you print the data.
I'm sorry, I've tried it several times, but now it does work.
if(Serial.available()>0){
state=Serial.read();
if (state==44){
state1=Serial.read();
if (state1==120){
X=Serial.read();
}
So, the ',' arrives. You store that character in a variable (stupidly) named state. That character is a comma (which is what you should have compared to), so you read a byte that hasn't arrived yet. Does that REALLY seem like a good idea?
state=Serial.read();
if (state==44){
state1=Serial.read();
if (state1==120){
X=Serial.read();
}
So, the ',' arrives. You store that character in a variable (stupidly) named state. That character is a comma (which is what you should have compared to), so you read a byte that hasn't arrived yet. Does that REALLY seem like a good idea?
I do not know very much about programming arduino.
what is the best way to do it?