The values are further partitioned between control characters, alpha characters, digits, punctuation and several types of space characters.
Look up the functions isupper() or islower(), iscntrl(), isdigit(), ispunct() and isspace() to make a determination of which partition the id is a member of first.
Once partitioned into type your example for a digit would be
int id is holding value 256 i.e. if represented in ascii form it must be 50,53,54.
in other words int value 256 must be written via serial.write to the screen. As serial.write cant write 256 I converted to be able to write to the screen.
But in my opinion code is too big for that small problem. So I am wondering if there is a shorter way ?
in my case id is always a number. if id=48 then in ascii must be 52,56 but not char '0'.
Do you want to see this figure(256) as it is on the Serial Monitor?
Do you know that Serial Monitor is an ASCII display unit? ASCII display unit means -- if we want to see a character (A to Z, a -z, 0 - 9, punctuation marks) on the Serial Monitor, we need to send to the Serial Monitor the ASCII code of that character. Thus --
1. to see 2, we need to send: 0x32 --> Serial.write(0x32); --> Serial.write (50); --> Serial.write(2 + 0x30);--> Serial.write(2 + 48);
2. to see 5, we need to send: 0x35 --> Serial.write(0x35); --> Serial.write (53); --> Serial.write(5+ 0x30); --> Serial.write(5 + 48);
3. to see 6, we need to send: 0x36 --> Serial.write(0x36); --> Serial.write (54); --> Serial.write(6 + 0x30); --> Serial.write (6 + 48);
Now, the question comes -- how to show the digits of an unknown id of type integer (4-digit id : 0000 - 9999). We need to write program for it?
@GolamMostafa
My function is doing exactly what you wrote its separating digits from numbers then doing conversion. I was searching for a shorter way of doing same thing.
I cant use serial.print . I would like to but with serial.print im getting not all chars on the other side. Only serial.write is working. Its not a screen its esp8266 and it accepts ascii only.
No need to write the whole code i did it already in one of my other posts.
Simple code like this is not working:
Serial.begin(115200);
Myserial.begin(115200); //softserial
And in loop
Myserial.println(“AT”); //to send with \r\n
Esp is getting only ‘A’ or sometimes unknown char after ‘A’.
With speed of 9600 things are getting even worse. It may not get anything.
With serial write no problem. So all my strings im breaking in loop to send byte by byte with 1ms delay. Without 1ms delay again not always chara are getting to esp. That way even string with 200chars is getting to the destination.
For logic converting i build small curcuit with n-type mosfets.
Tried without softwareserial directly to rx and tx feedback via led. Same problem write works println doesnt.
UKHeliBob:
Can you please post a simple but complete program that sends the data and a short but complete program that receives the data that shows the problem.
I paid attention to different words in the request I think :(.
But these are the functions that receive and send. Will edit to make it smaller.