11 years, 3 months ago.

Sending a float across a serial connection _

i need to send float from the pc and recieve float from mbed.

1 Answer

11 years, 3 months ago.

Hi Rouabhia,

This thread probably has what you need:

Andy's solution is a neat and standard way:

typedef union _data {
  float f;
  char  s[4];
} myData;
 
#include "mbed.h"
 
Serial pc(USBTX, USBRX);
 
myData q;
 
int main() {
  q.f = 1.234;
  pc.printf("%c%c%c%c", q.s[0], q.s[1], q.s[2], q.s[3]);
}

Simon