That's very cool.
I'm trying to replicate it to learn how to use the sensors. I think I understand what's happening in your logic, guessing that you are comparing if the latest output on some axis in the accelerometer has changed in the past 2 ms if...