Shop OBEX P1 Docs P2 Docs Learn Events
How to change main program to sub program? — Parallax Forums

How to change main program to sub program?

Chris GeorgiadisChris Georgiadis Posts: 5
edited 2008-02-16 22:52 in Robotics
How to change main program to sub program (not subroutine) by pressing a pushbutton?

Is that possible?

Comments

  • UghaUgha Posts: 543
    edited 2008-02-16 13:59
    Do you mean having multiple programs in a signal BS2?

    That's not possible... but other things are.

    Please clarify.
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2008-02-16 17:01
    Hi Chris, you can have more than one routine in the BS2 that you could switch between using conditional statements. If your routines are large you might consider·one of the·multi slot Stamps.

    x VAR byte

    main:
    DEBUG "Program 1", CR
    x=x+1
    IF x> 50 THEN x=0:GOTO main2
    PAUSE 100
    GOTO main

    main2:
    DEBUG "Program 2", CR
    x=x+1
    IF x> 50 THEN x=0:GOTO main
    PAUSE 100
    GOTO main2

    Jeff T.
  • Chris GeorgiadisChris Georgiadis Posts: 5
    edited 2008-02-16 19:45
    thanx for the reply, but i don't understand the meaning of "x".
    how to change its value so to change the routine from main to main2?
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2008-02-16 20:52
    Chris -

    Normally, the variable "X" (or whatever variable is similar in some given program) can have its value assigned as follows (examples only):

    1. In the beginning of the program as a user-supplied constant

    2. As the result of a computation done within the program

    3. From some external source

    a. A rotary knob encoder (0-9)
    b. A program on a PC which transmits the value to the Stamp
    c. A program on another Stamp which transmits the value to this one
    d. A keypad or other input device
    e. The DEBUGIN command (see the PBASIC Reference Manual)
    f. As data read from a EEPROM or other memory related device

    That should give you some understanding of how "X" can be derived. I'm sure there are other means which I've neglected to include, merely due to my oversight.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "Genius is one percent inspiration and ninety-nine percent perspiration."

    Thomas Alva Edison
  • Chris GeorgiadisChris Georgiadis Posts: 5
    edited 2008-02-16 21:09
    yes but because i 'm new, can you describe how can i give the variable "x" an input 1 and 0 from a pushswitch?

    example: If i push the button then the "x" must be 1 and if not 0
  • FranklinFranklin Posts: 4,747
    edited 2008-02-16 21:26
    Check in the help file for 'button'

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2008-02-16 21:56
    Chris -

    This is against my better judgement to provide such a routine, only because it doesn't represent a complete or practical program. However, here is an example.

    In this example a PBASIC Stamp BS-2 is presumed to be the target processor, and the switch is presumed to be momentary contact, and wired to Pin Port one of the Stamp.

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

    ' Assign Pin Port to external switch

    Switch PIN 1

    'Assign RAM Variables

    X VAR BYTE

    Main:

    X = 0

    Fetch_Input:

    'X will be 0 if the button is NOT pressed or 1 if it IS pressed
    X = Switch

    IF X = 1 THEN GOTO Switch_Pressed
    IF X = 0 THEN GOTO Fetch_Input

    Switch_Pressed:

    'Do something here when the switch is pressed

    GOTO Fetch_Input

    END


    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "Genius is one percent inspiration and ninety-nine percent perspiration."

    Thomas Alva Edison
  • Chris GeorgiadisChris Georgiadis Posts: 5
    edited 2008-02-16 22:52
    many thanx i'll try it.
Sign In or Register to comment.