# ON...GOSUB Example

{PBASIC 2.5}

Syntax: NAP

NOTE: The example below is written for the BS2 and will run on any of the BS2-family modules. Modify the $STAMP directive (as required) before downloading to the BS2e, BS2sx, BS2p, BS2pe, or BS2px.

    ' ON-GOSUB.BS2
    ' This program demonstrates a simple task manager that can be used in
    ' a variety of applications.  It is particularly useful in robotics and
    ' industrial applications.  The advantage of this design is that task
    ' code modules may be called from other places in the program, including
    ' other tasks, and the overal program flow is maintained.

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    task            VAR     Nib

    Main:
      DO
        ON task GOSUB Task_0, Task_1, Task_2        ' run current task
        task = task + 1 // 3                        ' update task pointer
        PAUSE 1000
      LOOP
      END

    Task_0:
      DEBUG "Running Task 0", CR
      RETURN

    Task_1:
      DEBUG "Running Task 1", CR
      RETURN

    Task_2:
      DEBUG "Running Task 2", CR
      RETURN

Go to Welcome page

BASIC Stamp Help Version 2.5.4

Copyright © Parallax Inc.

8/8/2012