ltmhall
04-13-2007, 10:03 PM
· I'm writing a program that will listen for a sound and when it detects it pauses for a few seconds
and checks to see if the sound is still there. I have written a routine and I wanted to know if there is
·an easier way to write it using less code than I have.
detectsound········· VAR ·····Bit
count····················· VAR ·····Bit
pulseCount···· VAR···· Byte
·
' -----[ Main Routine ]-------------------------------------------------------
DO
GOSUB check_sound1
Loop
' -----[ Subroutines ]--------------------------------------------------------
check_sound1: ···············································‘ Program to check sound
count = 0·· ·················································· ····‘set value of count to zero···············
IF (detectsound = 1) Then·············· ················‘ if detect sound detect sound = 1
count =·1··········· ··············································‘ adds 1 to the value of count
PAUSE 3000······································· ············‘ pause for a short time
GOTO check_sound2························· ·············‘ now ready to check if sound is still there
ELSE····················· ··········································‘ if no sound found return
END IF
Return
·
check_sound2······································ ··············· ·‘checks again for sound
If (detectsound =1) Then· ································‘ if sound found again detectsound = 1
count = 1+count··············· ································‘ increments count by one again
Goto found_sound············ ·······························‘ found sound
Else··································· ·······························‘ if not return
Endif
return
·
found_sound:························ ····························‘found sound
If (count > 2) Then ············································‘ one more check for sound
GOSUB Backwards
GOSUB Backwards
GOSUB Right
Else
Return
·
Back_Up: ·······························' Back up.
FOR pulseCount = 0 TO 40
PULSOUT 13, 650
PULSOUT 12, 850
PAUSE 20
NEXT
·
Turn_Right:
FOR pulseCount = 0 TO 20 ···············' Right turn, about 90-degrees.
PULSOUT 13, 850
PULSOUT 12, 850
PAUSE 20
NEXT
RETURN
·
and checks to see if the sound is still there. I have written a routine and I wanted to know if there is
·an easier way to write it using less code than I have.
detectsound········· VAR ·····Bit
count····················· VAR ·····Bit
pulseCount···· VAR···· Byte
·
' -----[ Main Routine ]-------------------------------------------------------
DO
GOSUB check_sound1
Loop
' -----[ Subroutines ]--------------------------------------------------------
check_sound1: ···············································‘ Program to check sound
count = 0·· ·················································· ····‘set value of count to zero···············
IF (detectsound = 1) Then·············· ················‘ if detect sound detect sound = 1
count =·1··········· ··············································‘ adds 1 to the value of count
PAUSE 3000······································· ············‘ pause for a short time
GOTO check_sound2························· ·············‘ now ready to check if sound is still there
ELSE····················· ··········································‘ if no sound found return
END IF
Return
·
check_sound2······································ ··············· ·‘checks again for sound
If (detectsound =1) Then· ································‘ if sound found again detectsound = 1
count = 1+count··············· ································‘ increments count by one again
Goto found_sound············ ·······························‘ found sound
Else··································· ·······························‘ if not return
Endif
return
·
found_sound:························ ····························‘found sound
If (count > 2) Then ············································‘ one more check for sound
GOSUB Backwards
GOSUB Backwards
GOSUB Right
Else
Return
·
Back_Up: ·······························' Back up.
FOR pulseCount = 0 TO 40
PULSOUT 13, 650
PULSOUT 12, 850
PAUSE 20
NEXT
·
Turn_Right:
FOR pulseCount = 0 TO 20 ···············' Right turn, about 90-degrees.
PULSOUT 13, 850
PULSOUT 12, 850
PAUSE 20
NEXT
RETURN
·