Make constants actually const.
Lots of cleanup.

 * Make all indentation 2 spaces
 * Split out the pulse code from getDistance into a new function
 * Cleanup the median calculation code.