Yet another basic PBasic problem! Thanks!
koolitude
Posts: 37
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?
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
Try putting one after the PAUSE 20 in the Turnleft routine
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
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!
I'm sorry that I keep asking these simple questions as I am still not used to the syntax... Really appreciate all your helps!