PBASIC Syntax

Quick Question - When using a DO…LOOP WHILE, is the following syntax acceptable?

                       Do 

            drive_R = 254
            drive_L = 254
 	    
            Loop While sForward = 1

Or do I need to use parentheses? Or possibly brackets?

Thanks in advance,

That’s just fine. It tokenizes perfectly for me.

Hmm, well, I only tried on RoboEMU. This might be an issue. I’ll try a RC soon and I’ll report the results.

One thing: syntacticly that is correct. In terms of working on an RC, it’s going to give you a BASIC RUN error. To avoid this, put a SERIN and SEROUT inside the loop. Or, ditch the DO…WHILE and router everything through your normal serin and serout. I suppose a gosub could accomplish the same thing from within the DO WHILE…

Actually, I had a GOSUB GoSerout within the Do … Loop that I removed before posting. That didn’t work because it wouldn’t RETURN to my Loop, or it would accidentally hit that GoSerout during the MainLoop.

In this case, I placed a SERIN and a SEROUT within theh Do … Loop itself. Question - Can I remove values of the SERIN, SEROUT commands that I don’t use? For example, everything except PWM1 - 4?

Thanks a lot,

*Originally posted by Goya *
Can I remove values of the SERIN, SEROUT commands that I don’t use? For example, everything except PWM1 - 4?

I THINK you can get away with leaving off values as long as they are the last N parameters. I think the two 255s at the start of the serout will cause the RC to treat it as all good.

the two 255’s indicate the beginning of a new serout. i learned that the hard way :). don’t be stupid like me, make sure no 255’s come in sequence after the initial ones :p. i also think the uP may put a 127/0 to any unused outputs, but don’t count me on this one, cause i’m not 100% sure.

*Originally posted by Ian W. *
**the two 255’s indicate the beginning of a new serout. i learned that the hard way :). don’t be stupid like me, make sure no 255’s come in sequence after the initial ones :p. i also think the uP may put a 127/0 to any unused outputs, but don’t count me on this one, cause i’m not 100% sure. **

You are correct.

You CAN remove stuff from the SEROUT. You CANNOT remove stuff from the serin or you will get BASIC INIT errors.

As for the gosub, it is possible, but takes some reworking of the other parts of the code. You main loop would have to be:

Do
gosub mySerin

'normal code goes here, including your loop that you posted originally.

gosub mySerout
Loop

mySerin:
Serin …
return

mySerout:
Serout …
return