gosub and if-then working together?


Results 1 to 3 of 3

Threaded View

  1. #1
    Join Date
    Nov 2004
    Location
    Saskatchewan Canada
    Posts
    189

    Default gosub and if-then working together?

    In the following bit of code there is a delay while waiting for a button to be pressed. If any of the buttons is pressed before the delay is up then a second routine is called to make a sound.

    It works as I have written it, but I have noticed that the first loop that is looking for the button presses appears to "reset" if one is pressed and starts the counting again.

    Is this normal operation when used this way? I'd just like to know. I know I could re-write this bit to remove that affect, but being still green on this I'm curious as to the why behind it.

    Thanks.

    Bart

    Code:
    errorcheck:                                                                     
    
        for loop = 1 to 4000                        ' short delay once sound program is selected
        getbutton = GPIO & %00110101		' get port values and keep only ports 0,2,4,5
        pause 1
        if getbutton <> 0 then gosub errortone      ' if a button is pressed play error tone
        next 
        return                                      ' return after delay and/or error routine
    
    errortone:                                      ' routine to produce a tone for any errors encountered
                                                                                    
        for loop = 1 to 3                                                           
        pause 16
        sound TRANSDUCER, [75, 5, 135, 5, 75, 2]                                              
        next loop
        return
    Last edited by bartman; - 23rd November 2005 at 04:43.

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts