Hmmmmm.... try putting the trig = 0 before the main loop:
Code:trig = 0 ' start output in LOW state main: GOSUB distance SELECT CASE dist CASE 0 ' PULSIN timed out and returns zero, turns LED OFF LOW led CASE IS < 8 ' dist <8 inches but not zero, turns ON LED HIGH led CASE ELSE ' dist >8 inches turns LED OFF LOW led END SELECT GOTO main distance: PULSOUT trig,1 ' each count = 10us PULSIN sens,1,dist ' will time out in 655ms if nothing received dist= dist/15 'convert to inches PAUSE 100 RETURN END




Bookmarks