Improved calibration function for Teensy 3.1 compatibility

Changed some integer type defs to avoid spurrious results