Shop OBEX P1 Docs P2 Docs Learn Events
eliminating or substitutes for a DO / LOOP — Parallax Forums

eliminating or substitutes for a DO / LOOP

gc3076gc3076 Posts: 44
edited 2006-02-14 19:21 in BASIC Stamp
I have tried to code a project in two stages and in doing so have created (2)·DO/LOOPs in each stage of the project.

The problem I now encounter is·when I merged the two programs. The way I merged was·I made the main body of each project a GOSUB and·moved the DO / LOOP·to encompass the whole project. However this still leaves a set of DO-LOOPs in each of the newly created GOSUBs. This prevents the merged·code from working coreectly. I have checked with the DEBUG that each work correctly ·independantly.

Is there a way to change the code so that something other than a DO/LOOP· is used in these newly created subroutines ? Thus giving the same result but not preventing the code from executing on?

Comments

  • Lee HarkerLee Harker Posts: 104
    edited 2006-02-14 14:29
    I don't think it is entirely clear what you intend to do. It is akin to saying you'd like to do addition without using the plus sign. You would use a loop where necessary and don't use one if it is not. Maybe you could post your code for people to see and make a determination from that.

    Lee Harker
  • Tronic (Greece)Tronic (Greece) Posts: 130
    edited 2006-02-14 14:37
    Why don't you try adding an escape variable on each do loop and place then on subroutines...
    The escape variable can cossists by I/O input too...

    example code:


    GOSUB part1
    GOSUB part2

    part1:
    DO
    .
    .
    .
    LOOP WHILE (IN4 = 1)
    RETURN

    part2:
    DO
    .
    .
    .
    LOOP WHILE (variable = 0)
    RETURN
  • Paul BakerPaul Baker Posts: 6,351
    edited 2006-02-14 15:46
    Lee is quite right that we can't give you proper advice without knowing more detail on what it is you want to do. If you need to have both do-loops processed at the same time, you should merge the two into a single do-loop. But without further deatail, I dont know if this will do what you want. As a side note if you are not placing WHILE or UNTIL after either the DO or LOOP or have an EXIT in the body of the DO...LOOP your loop is never exited and there is no need to place it in a subroutine, because it will never leave the subroutine as subroutines are designed to.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·1+1=10
  • gc3076gc3076 Posts: 44
    edited 2006-02-14 16:50
    Reset:
    running = 1

    '
    [noparse][[/noparse] Program Code hall sensor]

    Main:
    DO ' will be moved to encompass whole program
    GOSUB Check_Sensor ' scan the sensor
    CW_rotation = CW_rotation + (hall_sensor * running) ' update count when running
    DO WHILE (hall_sensor = 1) ' would like to delete
    GOSUB Check_Sensor
    SEROUT LcdPin, LcdBaudMode, [noparse][[/noparse]LcdStart, LcdCls, LcdOn]
    SEROUT LcdPin,LcdBaudMode, [noparse][[/noparse]Line1, "CW count:"]
    SEROUT Lcdpin, LcdBaudMode,LcdCls, [noparse][[/noparse]" ", DEC CW_rotation]
    LOOP ' would like to delete
    LOOP' will be moved to encompass whole program

    END

    '
    [noparse][[/noparse] Subroutine hall-sensor ]

    Check_Sensor:
    hall_sensor = 1 ' assume active
    hall_sensor = hall_sensor & ~A_hall_pin ' hall sensor stays active
    PAUSE 1

    RETURN
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-02-14 18:41
    gc3076 -

    Perhaps I'm missing something, but why can't you just do this:

    Main:
    ··· GOSUB Check_Sensor························· ' scan the sensor
    ······ CW_rotation = CW_rotation + (hall_sensor * running)······· ' update count when running
    ··· DO WHILE (hall_sensor = 1)······················ ' would like to delete
    ········· GOSUB Check_Sensor
    ····· SEROUT LcdPin, LcdBaudMode, [noparse][[/noparse]LcdStart, LcdCls, LcdOn]
    ····· SEROUT LcdPin,LcdBaudMode, [noparse][[/noparse]Line1, "CW count:"]
    ····· SEROUT Lcdpin, LcdBaudMode,LcdCls, [noparse][[/noparse]" ", DEC CW_rotation]
    ··· LOOP· ' would like to delete
    ··GOTO Main:

    · END

    '
    [noparse][[/noparse] Subroutine hall-sensor ]

    Check_Sensor:
    hall_sensor = 1········· ' assume active
    hall_sensor = hall_sensor & ~A_hall_pin· ' hall sensor stays active
    ··· PAUSE 1
    · RETURN

    I'm just not sure how or why you were planning to exit the enitre thing.

    Regards,

    Bruce Bates


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • gc3076gc3076 Posts: 44
    edited 2006-02-14 19:21
    Sorry, I messed up last posting.

    The reason I want to get rid of the DO/LOOP is this portion below is going to be merged into another portion of· code and the below·is an endless loop.

    I am trying to display two constantly changing values on a 2x16 LCD display. Line0 displays one result and Line1 displays the other. I have both portions of code working independantly however when they merge I can't get past the below.

    Probably the way I am counting is not the best?

    Main:
    ··· GOSUB Check_Sensor························· ' scan the sensor
    ······ CW_rotation = CW_rotation + (hall_sensor * running)······· ' update count when running
    ··· DO WHILE (hall_sensor = 1)······················ ' would like to delete
    ········· GOSUB Check_Sensor
    ····· SEROUT LcdPin, LcdBaudMode, [noparse][[/noparse]LcdStart, LcdCls, LcdOn]
    ····· SEROUT LcdPin,LcdBaudMode, [noparse][[/noparse]Line1, "CW count:"]
    ····· SEROUT Lcdpin, LcdBaudMode,LcdCls, [noparse][[/noparse]" ", DEC CW_rotation]
    ··· LOOP· ' would like to delete
    ··GOTO Main:

    · END

    '
    [noparse][[/noparse] Subroutine hall-sensor ]

    Check_Sensor:
    hall_sensor = 1········· ' assume active
    hall_sensor = hall_sensor & ~A_hall_pin· ' hall sensor stays active
    ··· PAUSE 1
    · RETURN
Sign In or Register to comment.