Author Topic: Tilting Trigger on the Accelerometer  (Read 4009 times)

Nick_W

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: Tilting Trigger on the Accelerometer
« Reply #15 on: February 27, 2017, 05:40:47 pm »
You're decoding the float wrong. The floats are 4 bytes little endian.

What you get is:
1 byte (0x08) - which decodes as 8
4 bytes of integer (0x02000000) - which decodes as 2
4 bytes of float (0x6f12833c) - which decodes as 0.016

1 byte (0x08) - which decodes as 8
4 bytes of integer (0x01000000) - which decodes as 1
4 bytes of float (0x250681bf) - which decodes as -1.008

1 byte (0x08) - which decodes as 8
4 bytes of integer (0x00000000) - which decodes as 0
4 bytes of float (0xa69b443d) - which decodes as 0.048

Exactly as expected.

You were putting three bytes of 0x00 before the float to decode. Remember byte = 1 bytes, integer = 4 bytes, float = 4 bytes - total 9 bytes.