Play once per button press without repeating while holding button down
Gabrielroto
Posts: 7
I would like to be able to play a sound file only once whether I hold in the button or not. The user should have to let go of the button and press it again to play the sound file again. That is, I don't want the sound file to repeat if I hold the button down. Any suggestions would be greatly appreciated.
Code snippet:
mp3 VAR Byte 'mp3 file number
mp3bit0 VAR mp3.BIT0 'mp3 bit 0
mp3bit1 VAR mp3.BIT1 'mp3 bit 1
mp3bit2 VAR mp3.BIT2 'mp3 bit 2
mp3bit3 VAR mp3.BIT3 'mp3 bit 3
mp3bit4 VAR mp3.BIT4 'mp3 bit 4
mp3bit5 VAR mp3.BIT5 'mp3 bit 5
mp3bit6 VAR mp3.BIT6 'mp3 bit 6
mp3bit7 VAR mp3.BIT7 'mp3 bit 7
main:
DEBUG? mp3,CR
AUXIO
IF IN15 = 0 THEN
mp3 = 1
GOTO playMP3
ELSEIF IN14 = 0 THEN
mp3 = 2
GOTO playMP3
ELSEIF IN13 = 0 THEN
mp3 = 3
GOTO playMP3
ELSEIF IN12 = 0 THEN
mp3 = 4
GOTO playMP3
ELSEIF IN11 = 0 THEN
mp3 = 5
GOTO playMP3
ELSEIF IN10 = 0 THEN
mp3 = 6
GOTO playMP3
ELSEIF IN9 = 0 THEN
mp3 = 7
GOTO playMP3
ELSEIF IN8 = 0 THEN
mp3 = 8
GOTO playMP3
ELSEIF IN7 = 0 THEN
mp3 = 9
GOTO playMP3
ELSEIF IN6 = 0 THEN
mp3 = 10
GOTO playMP3
ENDIF
GOTO main
playMP3:
MAINIO
OUT0 = mp3bit0 'separate mp3 file name into 7 bits
OUT1 = mp3bit1
OUT2 = mp3bit2
OUT3 = mp3bit3
OUT4 = mp3bit4
OUT5 = mp3bit5
OUT6 = mp3bit6
OUT7 = 0
PAUSE 250 'short mp3 player T8 for at least 50ms
OUT7 = 1
GOTO main
Post Edited (Gabrielroto) : 3/25/2009 4:54:49 PM GMT
Code snippet:
mp3 VAR Byte 'mp3 file number
mp3bit0 VAR mp3.BIT0 'mp3 bit 0
mp3bit1 VAR mp3.BIT1 'mp3 bit 1
mp3bit2 VAR mp3.BIT2 'mp3 bit 2
mp3bit3 VAR mp3.BIT3 'mp3 bit 3
mp3bit4 VAR mp3.BIT4 'mp3 bit 4
mp3bit5 VAR mp3.BIT5 'mp3 bit 5
mp3bit6 VAR mp3.BIT6 'mp3 bit 6
mp3bit7 VAR mp3.BIT7 'mp3 bit 7
main:
DEBUG? mp3,CR
AUXIO
IF IN15 = 0 THEN
mp3 = 1
GOTO playMP3
ELSEIF IN14 = 0 THEN
mp3 = 2
GOTO playMP3
ELSEIF IN13 = 0 THEN
mp3 = 3
GOTO playMP3
ELSEIF IN12 = 0 THEN
mp3 = 4
GOTO playMP3
ELSEIF IN11 = 0 THEN
mp3 = 5
GOTO playMP3
ELSEIF IN10 = 0 THEN
mp3 = 6
GOTO playMP3
ELSEIF IN9 = 0 THEN
mp3 = 7
GOTO playMP3
ELSEIF IN8 = 0 THEN
mp3 = 8
GOTO playMP3
ELSEIF IN7 = 0 THEN
mp3 = 9
GOTO playMP3
ELSEIF IN6 = 0 THEN
mp3 = 10
GOTO playMP3
ENDIF
GOTO main
playMP3:
MAINIO
OUT0 = mp3bit0 'separate mp3 file name into 7 bits
OUT1 = mp3bit1
OUT2 = mp3bit2
OUT3 = mp3bit3
OUT4 = mp3bit4
OUT5 = mp3bit5
OUT6 = mp3bit6
OUT7 = 0
PAUSE 250 'short mp3 player T8 for at least 50ms
OUT7 = 1
GOTO main
Post Edited (Gabrielroto) : 3/25/2009 4:54:49 PM GMT
Comments
2) To do what you want, you have to first wait for all buttons to be released, then wait for a button to be pressed. This is called a "state machine" ... look up a description on the Wikipedia.