7 years, 1 month ago.

How can I receive a value from serial then do mathematical operations on it ?

I am still confused with the Serial communication in mbed. I want to receive a value via Serial (sensor reading for example), store that value in an int variable then manipulate it (math operations). In particular, I don't know how to use the getc() to do this as it reads the int representing the ASCII value of the received character.

I would appreciate if you can give me a small example that sends an integer value from Serial, store it then manipulate it in the program. or refer me to a code somewhere.

1 Answer

6 years, 11 months ago.

What it the format of the number? Binary or text?

If binary use getc() to read the bytes and then use bit operations to shift each byte to re-assemble the full number.

If text then what is the text format? For most text scanf() will do the job but it does depend on the formatting.

None of this is mbed specific, it's generic c code.