Shop OBEX P1 Docs P2 Docs Learn Events
Run two program in one stamp with one Pin by switch — Parallax Forums

Run two program in one stamp with one Pin by switch

TomvnTomvn Posts: 103
edited 2011-01-01 12:05 in BASIC Stamp
This my sample program

HIGH 11 ' the problem when this pin in high it just run the main_loop
Main:

IF OUT11 = 1 THEN GOSUB main_loop ' this must wait until switch turn on
IF OUT11 = 0 THEN GOSUB recieve_mode ' i need this run first until switch turn

RETURN

Any help thanks.

Comments

  • Clive WakehamClive Wakeham Posts: 152
    edited 2010-12-31 04:52
    You have the commands mixed up. Because how you have written it will always run the main_loop since thats the value your using with the "High 11" command.

    If the switch is connected to pin 11 then you need to replace the "if Out11=" with "if in11="

    Also have you a pull-up resistor on the line to start it with a known value?
  • TomvnTomvn Posts: 103
    edited 2010-12-31 12:35
    Hi Clive,
    i try what you say , but still have that problem , so anyway to make the main_loop run together with recieve_mode , i main it two program run at same time , because i have two bs2 run on this one project so the main_loop it that for say it module and the recieve_mode that recieve byte from the master bs2

    This my sample program

    HIGH 11 ' the problem when this pin in high it just run the main_loop
    Main:

    IF in11 = 1 THEN GOSUB main_loop ' this must wait until switch turn on
    IF in11 = 0 THEN GOSUB recieve_mode ' i need this run first until switch turn

    RETURN
  • Clive WakehamClive Wakeham Posts: 152
    edited 2010-12-31 14:25
    There must be a misunderstanding between our communication.

    Why are you using High11?
    Have you an external switch connected to pin 11?
  • FranklinFranklin Posts: 4,747
    edited 2010-12-31 14:34
    Tomvin, two things. Let's stick with the simple program and get that fixed before we post large amounts of code that make finding the problem that much harder. Second when you post code you need to 'wrap' the code with code tags so it will format correctly.
    You need to be
      in advanced mode
        to do that. (or just use the tags)
    
    Show us the fixed sample code you tried.
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2010-12-31 16:32
    This my sample program

    HIGH 11 ' the problem when this pin in high it just run the main_loop
    Main:

    IF OUT11 = 1 THEN GOSUB main_loop ' this must wait until switch turn on
    IF OUT11 = 0 THEN GOSUB receive_mode ' i need this run first until switch turn

    RETURN


    Are you want to use an input on a Basic Stamp if this is the case then the command would be

    this

    Mode VAR IN11

    DO

    IF Mode = 0 THEN
    GOSUB Receive_Mode

    ELSE

    GOSUB main_Mode

    ENDIF

    LOOP



    Main_Mode:

    'Your code

    RETURN

    Receive_Mode:

    'Your code

    RETURN


    Below is a code routine doing just what your are asking to do in my routine you have to power down the Basic Stamp to change modes but I could have written so I could have done with out turning



    Keep in that if you want change modes you are going to have to put this in a DO LOOP



    IF OUT11 = 1 THEN GOSUB main_loop
    IF OUT11 = 0 THEN GOSUB receive_mode



    Using OUT11 = 1 and then right after using OUT11 = 0 is not a good habit to get into
  • TomvnTomvn Posts: 103
    edited 2011-01-01 12:05
    Sorry Franklin iam long time not come to forum so forget what to do.
    Hi Clive i used external switch to connect to Pin 11, like i say i have use two Bs2 to connect together by Pin11 because my project need many I/O so one Bs2 not enough for it so that why i need run two program in one stamp the master stamp with all the sensor and the second with some light servo anh say it module , but say it module it have run in loop mode, i know Bs2 stamp just do one stack a time so the switch may help on this.
    Sam_Sam_Sam i try your code but not work , any help thanks.
Sign In or Register to comment.