ADXL345 Persistance of Vision problem...

Hi Everyone,

I’ve got a pro-mini attached to 10 LED’s and an ADXL 345 with an I2C interface.

I cannot for the life of me figure out how to interpret when the wand changes direction.

When I had it pieced together with an UNO, my setup was heavy and unwieldy, now it is all very light, and can move very quickly.

On the UNO, I had picked arbitrary numbers to determine if the wand had changed direction or not, but now with the new setup, there is too much variation between a big “swing” and a little “swing” to use those arbitrary numbers.

My sketch has two “words” i want to display with my POV, one word for each direction of movement.

I’ve tried to use a “peak detection” algorithm but it doesn’t work like I had hoped…

I’m using the Y axis data for my math, although I read all three axes. I had expected to see the acceleration diminish to 0 at the end or beginning of a cycle, but the highest numbers in the data correspond to the leftmost travel of the wand. The lowest negative numbers correspond to the rightmost travel of the wand.

I’ve also included a column of my data with the elapsed time between samples. (see link below)

The sketch as uploaded has most of the stuff commented out just so I could capture some data.

Any suggestions would be super helpful, I’ve been working on this for a few days and I’m going nuts!

Here is a link to my (lousy / messy) code, and to a sample of the data.

I’m sure I’m not understanding something easy… :frowning:

Thanks for your help!

http://pastebin.com/rFUnHygA <-Link to sketch

http://pastebin.com/fBPkPBsf ← Link to data