Hello and welcome to our community! Is this your first visit?

Blog Comments

  1. vedder's Avatar
    Thats pretty kick ass!
  2. ala42's Avatar
    Right, I should have explained that *4/125 is like *32/1000, it just keeps the numbers smaller. I wanted to be sure that (receiverData[AUX]-1000 + halfBit) * factor stays in 16 bit int range even if receiverdata is a bit larger or smaller than expected, so I reduced the fraction.
  3. wilafau's Avatar
    ala42 - Very very clever!! Since the receiver value is already binary coded mapped to the range 1000-2000 it is simply a matter of dividing by the mapping factor to turn it back into the original binary code. As you said the halfbit makes sure you hit the middle of the range. Took me a moment to figure out that *4 / 125 is actually the same as dividing by the scale factor 1/(1000 / 2^5) = 1/31.25 = 4/125.

    I'll give it a try and check that I don't still have a little issue with the LSB in practice.

    Now if only the BB codes would get turned back on I'd update the post!
  4. ala42's Avatar
    The calculation gets a lot easier when you map the input range of 1000-2000 to 0-2^5 for your 5 switches (0-32), e.g.
    halfBit = 1000/32/2;
    aval = ((receiverData[AUX]-1000 + halfBit) * 4) / 125

    Now each bit in aval represents one of your five switches. The shift by halfBit makes sure you hit the range in the middle.
  5. luc's Avatar
    I'm sure it's gonna be a great help to me. Saves me the hassle of looking up things, and getting what i need to know straight away.
    Thanks for sharing.