I know you said you already solved the coding part, but
this thread extensively covers this topic.
Edit:
If you want to take a look at the low pass filter I mention, PM me. The version in the papers contains a slight bug. (Well, ok, it's fatal... but only if you push the joystick all the way forward.

)