Questions about this sort of thing arise from time to time, so I've written this generalized routine that should work for most people. In this example, it detects when 3 events occur within any 10 seconds. Change the Events constant and the Interval constant as required. Uses the M2 parts system variable Timer. Events can be anything that cause a resettable logic level change on a pin. A button for example, but would also work with a sound detector, vibration, temperature etc..
Code:
'Detect events within time interval
'Boris Burke JUN 2013
'
'Detects when a set number of events happen within a set amount of time
'Requires one byte variable
'Works only on M2 parts
symbol events=3 'number of events to detect
symbol interval=10 'number of interval seconds, must be 1 or more
symbol event_count=b0 'stores current number of valid events
do
if pin1=1 then 'detect event on pin1
do: loop until pin1=0 'wait for event reset
inc event_count 'increment event count
if time>=interval then 'test if event is outside time interval
time=0 'reset timer
event_count=1 'reset event count
endif
endif
loop until event_count=events 'continue until correct number of events occur within time