Shop OBEX P1 Docs P2 Docs Learn Events
Yet another basic PBasic problem! Thanks! — Parallax Forums

Yet another basic PBasic problem! Thanks!

koolitudekoolitude Posts: 37
edited 2007-02-25 17:08 in BASIC Stamp
I am coding a simple program for controlling the servo motors of my robot. I cannot figure what are the differences between the following two programs. The first one works but the second one doesn't. Please help.

First Program:

ServoL CON 12
ServoR CON 13

Main:
PULSOUT ServoL, 750
PULSOUT ServoR, 700
PAUSE 20
GOTO Main



Second Program:

ServoL CON 12
ServoR CON 13

Main:
GOSUB TurnLeft
GOTO Main

TurnLeft:
PULSOUT ServoL, 750
PULSOUT ServoR, 700
PAUSE 20


Why doesnt the second one work?

Comments

  • LarryLarry Posts: 212
    edited 2007-02-25 07:54
    every GOSUB needs a RETURN statement at the end of the routine it references.

    Try putting one after the PAUSE 20 in the Turnleft routine

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • Desy2820Desy2820 Posts: 138
    edited 2007-02-25 08:07
    Koolitude,

    The first program sets up an endless loop between Main and the last statement, GOTO Main.·

    In your second program, as the last line in your TURNLEFT subroutine,·add "RETURN."· This will send you back up into your main loop, which will just loop and call the subroutine again.· Once you're in a subroutine, until the program sees a RETURN the subroutine has control,·thus the program never goes back to MAIN to hit the GOTO.·

    (P.S. If using Parallax continous rotation servos, to actually turn left, you will need to adjust the PULSOUT values.· As written, the robot shouldn't move, because both servos should stop with a value of·about 750.)

    Check the PBasic manual for "GOSUB" and "RETURN" commands.

    Hope this helps!
  • koolitudekoolitude Posts: 37
    edited 2007-02-25 17:08
    Thank you very much!

    I'm sorry that I keep asking these simple questions as I am still not used to the syntax... Really appreciate all your helps!
Sign In or Register to comment.