I've been looking at some magnetic rotary encoders for a small rotary table and one of the recommendations was to average the output. This reduces the ability to record high rotation speeds but for my application this is not an issue as the table will be rotated by hand.
For numbers you can simply sum the values and then divide by the number of values. This does not work for angles because the numbers reset after 360. Luckily some mathematicians have worked it out already and have a solution using trigonometry.
For this to work with the Arduino you need to use floating point numbers hence the "double" data type and also the mathematics library.
My version of the code is over at Github, all I've done is swap stdio from the C example with serial.print.
There are a couple of things still to investigate. Firstly how much memory does this simple function take up (allowing for all the math functions in the background) and how long does it take to run.
I'm planning to use the function with a fixed number of angles to average (probably 2) so will likely "unroll" the loop in the averaging function.
Reminiscent of the SNES & PS Gamepad without the casing the Esplora board features an analog joystick on the left and four pushbuttons on the right.
The is a microcontroller board based on the Arduino Leonardo. The in unique to previous board from Arduino as it has built in onboard sensors for you to utilise without make additional purchases. The best thing out the is that it is designed for everyone from complete novices to seasoned veterans. Getting you first project off the ground should take minutes rather than days.....hopefully
The uses an Atmega32U4 AVR microcontroller with 16 MHz crystal oscillator, which is the same as the Leonardo board, plus a micro USB connection capable of acting as a USB client device, like a mouse or a keyboard in included.
Schematics & Reference Design
Fancy trying out the Esplora for FREE in exchange for a product review - Enrol in our latest RoadTest before the 5th August
Edit: Are you based in the UK? Arduino Esplora is now available from CPC