ping con 0 ' Set the number to free pin '0' Output to activate pinger. compRC con 1 ' Set the number to free pin '1' Output to set comparator RC circuit. rcvr con 2 ' Set the number to free pin '2' Input from 40kHz receiver/comparator. pingLen con 200 ' Duration of ping in 2-us units. echTime VAR word sonar: high ping ' Turn pinger off initially high compRC ' Raise C2 to +5 volts. pause 1 ' Allow time for C2 to reach +5V. input compRC ' Disconnect pin from C2. pulsout ping,pingLen ' Send a short 40kHz pulse. rctime rcvr,0,echTime ' Wait for echo; save time to echTime. if echTime < 150 then hurt if echTime > 149 then run return