0 registered members (),
1,118
guests, and 8
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
float to byte? serial input of float
#336144
08/01/10 21:21
08/01/10 21:21
|
Joined: Aug 2002
Posts: 164 Houston
Nicholas
OP
Member
|
OP
Member
Joined: Aug 2002
Posts: 164
Houston
|
I am trying to get a float value input through serial, but it's not working. I try a float value in Arduino and setup float value in 3dgs, but doesn't work. it only seems to work when both of them are setup as bytes.
Any idea how I can get this to work? I thought of converting the float to it's byte values and recombining them in lite-c after reading them in, but I don't know how to do this. It would be a lot easier to just read the float directly.
Black holes are where God divided by zero.
|
|
|
Re: float to byte? serial input of float
[Re: Lukas]
#336153
08/01/10 22:49
08/01/10 22:49
|
Joined: Aug 2002
Posts: 164 Houston
Nicholas
OP
Member
|
OP
Member
Joined: Aug 2002
Posts: 164
Houston
|
I can't seem to get that to work. it gives me 0 for each of those bytes, but I am trying to call them in a digits panel. Is there a way to verify that? and I'm not sure how to recombine them back. Would you be able to show me the code please.
I've also tried memcpy but not sure if it's working either byte bytez[4]; float f = 852140; var fa = f; memcpy( bytez, &f, sizeof(f) );
Black holes are where God divided by zero.
|
|
|
Re: float to byte? serial input of float
[Re: Lukas]
#336157
08/01/10 23:27
08/01/10 23:27
|
Joined: Aug 2002
Posts: 164 Houston
Nicholas
OP
Member
|
OP
Member
Joined: Aug 2002
Posts: 164
Houston
|
I was wondering about that, but wasn't sure. thanks, that definitly helps break it down, but how do I get them back into a float. I've heard that a union might work for that, but can't find a good example.
Black holes are where God divided by zero.
|
|
|
Re: float to byte? serial input of float
[Re: Lukas]
#336159
08/01/10 23:38
08/01/10 23:38
|
Joined: Aug 2002
Posts: 164 Houston
Nicholas
OP
Member
|
OP
Member
Joined: Aug 2002
Posts: 164
Houston
|
I didn't think it would be that easy. I hoped it would be but whenever I tried looking it up, nobody was giving memcpy as an example of how to recombine it. thanks for the help. I'm not used to this type of thing. ![grin grin](/ubb7/images/graemlins/default_dark/grin.gif)
Black holes are where God divided by zero.
|
|
|
|