Hello. I did something like this a long time ago. You can also experiment with the nap command, use word variables instead of bytes and change IF X <> Y Then... to if X > (Y + 001) to adjust sensitivity.
'12f675
@ DEVICE MCLR_OFF, INTRC_OSC, WDT_ON, BOD_ON, PWRT_ON, PROTECT_ON
ANSEL = 0 'all inputs digital adcin command converts to analog
CMCON = 7 'comparators off
trisio = %00000001 'input for piezo
GPIO = 0 'ALL LOW
X VAR BYTE
Y VAR BYTE
START:
ADCIN 1,X
NAP 0 'GIVES TIME BETWEEN SAMPLES
ADCIN 1,Y
IF X <> Y Then PLAY
GoTo START
play:
High GPIO.4 'RELAY ON
Pause 5000
Low GPIO.4 'RELAY OFF
GoTo START
Bookmarks