gosub and if-then working together?


Closed Thread
Results 1 to 3 of 3
  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.

  2. #2
    Join Date
    Aug 2005
    Posts
    57


    Did you find this post helpful? Yes | No

    Default

    The for to next loops in both routines are using the same loop variable "loop".

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


    Did you find this post helpful? Yes | No

    Default

    Darn. I was hoping to get back to this before someone else noticed!

    I copied and pasted that second part from a previous version of my program and didn't change the loop name. I thought of this as I was going to sleep last night.

    I'm surprised it even worked at all.

    Thanks,

    Bart

Members who have read this thread : 1

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