Gadgeteer Mini Pacman - New Enhancements

I just did the math and I think something is wrong…

I do not see how that is really different, it is nice that you could change the / to a shift, but the asymmetry issue remains, or did I miss something?

Btw. you will need a cast to double to get the ratio to work.

I would suggest you ignore the asymmetry, my gut feeling is that this is just an artifact of the underlying analog data being scaled to integer ranges. If you ignore the asymmetry which then this should do the trick?


private static double Normalize(int halfRange, int value)
{
  double result = (double)value / halfRange;
  return result < -1 ? -1 : result > 1 ? 1 : result;
}

I attached a quick screenshot of a test I ran. The only change I made to your code was to remove the -1 addition and added the cast to double. The second attachment includes the -1 addition, I thought I would test that just in case I missed something in the maths.

Doh!

Ok have tested it. Final version:

private static double Normalize(int min, int max, int value)
        {
            double result = -1.0 + (double)((value - min) << 1) / (max - min);
            return result < -1 ? -1 : result > 1 ? 1 : result;
        }

Maybe I have miss-understood the asymmetry of the wii-chuck controller(I think that is what it is called?). If the range is -10 to 25 (as an extreme example) is center 0 or 7?

It will be around 7 in this example. Assymetry is negligable it is like [-25;26]. I just wanted to make it generic.

Ah, it’s all clear now. Thank you for indulging me… As the saying goes, “trust the source” as soon as I saw your last code snippet I realized the mis-understanding on my part :slight_smile:

@ taylorza - It was very easy to add Chucky. Game running great! Thank you for the good design.

http://www.tinyclr.com/forum/topic?id=7326&page=2#msg71996

Send me an e-mail with your address, please. I will send you one module.

@ Architect - I am glad you found it useful. It was an excellent first experience with Gadgeteer.

@ taylorza Ive just been playing Pac Man on my spider. Ahhhh it takes me back to my youth :). What a great job you did, i am amazed at the speed of it.
For me the gadgeteer platform is a fantastic hobby alowing me to learn C# and electronics at the same time (big learning curve) but Pac Man really shows what can be achieved. A real inspiration :slight_smile:

@ HughB, nice avatar :slight_smile:

@ Gralin :slight_smile: thanks