Sound Implact Sensor Project with basic stamp 2

So I am working on a project using the Sound Impact sensor, and my objective is to be able to turn on a system (light or fan) when you blow into the impact sensor and when you blow into it twice it then turns off the system.
i was able to figure out the commands that will turn on the system was this

' {$STAMP BS2}
' {$PBASIC 2.5}
Main:
DIR1=1
DO
IF IN15 = 1 THEN
HIGH 1
PAUSE 500
ELSEIF IN15 = 0 THEN
LOW 1
ENDIF
LOOP
IF IN15 = 1 THEN

but I just don't know what to do to make the system know that I want to turn off the system when I blow into it twice, any help will be appreciated.

Why are you asking this question in an Arduino forum ?

@Denn1, try the PBasic forums here:- PBasic
Only Arduino here.