Improved calibration function for Teensy 3.1 compatibility

Chnged some integer type defs to avoid spurrious results.