'reading a PIR (passive infrared) sensor pirPin PIN 0 'input pin pirState VAR BIT 'current state of pin (0 or 1) pirStatePrev VAR BIT 'previous value pirCount VAR BYTE 'count of how many cycles pirPin has been HIGH INPUT 0 'make pin an input top: pirState = pirPin 'read pin IF pirState = 1 THEN pirCount = pirCount + 1 'if HIGH, increment count ENDIF IF pirState <> pirStatePrev THEN 'if state has changed pirStatePrev = pirState 'record current state DEBUG "state: ",DEC pirState IF pirState = 0 THEN 'if pin has gone LOW, reset count DEBUG " cycles ON: ",DEC pirCount ENDIF DEBUG CR ENDIF GOTO top ' CIRCUIT: ' ' __PIR___ ' | | | ' GND V+ OUT ' | | | ' | +5v |---INPUT_PIN ' | | ' |-----10k_ohm ' | ' GND