BS2sx skip line
Archiver
Posts: 46,084
Hello,
I'm stuck when trying to write a program in BS2, I'm looking for a
command or some way to skip a few lines in the code if certain
condition is satisfied. i.e.
IF freq = 0 THEN ?(skip the following two lines)
IF freq > 2000 AND freq <3500 THEN do_this
IF freq > 4000 AND freq <6000 THEN do_that
Anyone got any ideas, please help me.
Thanks
I'm stuck when trying to write a program in BS2, I'm looking for a
command or some way to skip a few lines in the code if certain
condition is satisfied. i.e.
IF freq = 0 THEN ?(skip the following two lines)
IF freq > 2000 AND freq <3500 THEN do_this
IF freq > 4000 AND freq <6000 THEN do_that
Anyone got any ideas, please help me.
Thanks
Comments
> I'm looking for a
> command or some way to skip a few lines in the code if certain
> condition is satisfied. i.e.
>
> IF freq = 0 THEN ?(skip the following two lines)
> IF freq > 2000 AND freq <3500 THEN do_this
> IF freq > 4000 AND freq <6000 THEN do_that
>
Like this?
IF freq = 0 THEN Skip_Lines ' Jumps to the label Skip_Lines
' when condition is
true.
IF freq > 2000 AND freq <3500 THEN do_this
IF freq > 4000 AND freq <6000 THEN do_that
Skip_Lines:
Saludos,
Aristides Alvarez
International Education Program Developer
aalvarez@p...
Parallax, Inc. www.parallax.com
California, USA
is the servo turns very slow when doing the "Go_straight,
Correct_right,Correct_left,Go_straight",i dont know why, the servo
does fine in another code. like in the following codes.
'Main program
Loop:
Left_sensor = IN1 'Monitor state of the pins here
Right_sensor = IN0
PULSIN FreqPin, 0, pHigh ' get high portion of input
PULSIN FreqPin, 1, pLow ' get low portion of input
period = (pHigh + pLow) */ Convert ' calculate cycle width in
uSecs
freq = 50000 / period * 20 ' calculate frequency
IF freq = 0 THEN Normal
IF freq > 2000 AND freq <3500 THEN Turn_right
IF freq > 4000 AND freq <6000 THEN Turn_left
Normal:
IF Left_sensor = 0 AND Right_sensor = 0 THEN Go_straight
IF Left_sensor = 1 AND Right_sensor = 0 THEN Correct_right
IF Left_sensor = 0 AND Right_sensor = 1 THEN Correct_left
IF Left_sensor = 1 AND Right_sensor = 1 THEN Go_straight
'Sub routines
Go_straight:
PULSOUT 2, 1500 'Servomotor is 90 degree (neutral position)
'PAUSE 5
GOTO Loop
Correct_right:
PULSOUT 2, 2100 'some small angle to the right
'PAUSE 5
GOTO Loop
Correct_left:
PULSOUT 2, 800 'some small angle to the left
'PAUSE 5
GOTO Loop
Turn_right:
FOR reps = 0 TO 190
PULSOUT 2, 2100
PAUSE 10
NEXT
FOR reps2 = 0 TO 190
PULSOUT 2, 800
PAUSE 10
NEXT
GOTO Loop
Turn_left:
FOR reps = 0 TO 190
PULSOUT 2, 800
PAUSE 10
NEXT
FOR reps2 = 0 TO 190
PULSOUT 2, 2100
PAUSE 10
NEXT
GOTO Loop
--- In basicstamps@yahoogroups.com, "Aristides Alvarez"
<aristidesparallax@y...> wrote:
> HelloLiang,
>
> > I'm looking for a
> > command or some way to skip a few lines in the code if certain
> > condition is satisfied. i.e.
> >
> > IF freq = 0 THEN ?(skip the following two lines)
> > IF freq > 2000 AND freq <3500 THEN do_this
> > IF freq > 4000 AND freq <6000 THEN do_that
> >
>
> Like this?
>
> IF freq = 0 THEN Skip_Lines ' Jumps to the label Skip_Lines
> ' when
condition is
> true.
> IF freq > 2000 AND freq <3500 THEN do_this
> IF freq > 4000 AND freq <6000 THEN do_that
> Skip_Lines:
>
> Saludos,
> Aristides Alvarez
> International Education Program Developer
> aalvarez@p...
> Parallax, Inc. www.parallax.com
> California, USA
goto Loop
Normal:
to handle spurious cases?
It's either that or you need a capacitor somewhere.(joking)
--- In basicstamps@yahoogroups.com, "Liang Xing" <lxing@c...> wrote:
> Thanks for the reply, I have tried that, however, the only problem
> is the servo turns very slow when doing the "Go_straight,
> Correct_right,Correct_left,Go_straight",i dont know why, the servo
> does fine in another code. like in the following codes.
>
>
>
> 'Main program
>
> Loop:
> Left_sensor = IN1 'Monitor state of the pins here
> Right_sensor = IN0
> PULSIN FreqPin, 0, pHigh ' get high portion of input
> PULSIN FreqPin, 1, pLow ' get low portion of input
> period = (pHigh + pLow) */ Convert ' calculate cycle width in
> uSecs
> freq = 50000 / period * 20 ' calculate frequency
>
> IF freq = 0 THEN Normal
> IF freq > 2000 AND freq <3500 THEN Turn_right
> IF freq > 4000 AND freq <6000 THEN Turn_left
>
> Normal:
> IF Left_sensor = 0 AND Right_sensor = 0 THEN Go_straight
> IF Left_sensor = 1 AND Right_sensor = 0 THEN Correct_right
> IF Left_sensor = 0 AND Right_sensor = 1 THEN Correct_left
> IF Left_sensor = 1 AND Right_sensor = 1 THEN Go_straight
>
> 'Sub routines
> Go_straight:
> PULSOUT 2, 1500 'Servomotor is 90 degree (neutral position)
> 'PAUSE 5
> GOTO Loop
>
> Correct_right:
> PULSOUT 2, 2100 'some small angle to the right
> 'PAUSE 5
> GOTO Loop
>
> Correct_left:
> PULSOUT 2, 800 'some small angle to the left
> 'PAUSE 5
> GOTO Loop
>
> Turn_right:
> FOR reps = 0 TO 190
> PULSOUT 2, 2100
> PAUSE 10
> NEXT
>
> FOR reps2 = 0 TO 190
> PULSOUT 2, 800
> PAUSE 10
> NEXT
>
> GOTO Loop
>
> Turn_left:
> FOR reps = 0 TO 190
> PULSOUT 2, 800
> PAUSE 10
> NEXT
>
> FOR reps2 = 0 TO 190
> PULSOUT 2, 2100
> PAUSE 10
> NEXT
>
> GOTO Loop
>
> --- In basicstamps@yahoogroups.com, "Aristides Alvarez"
> <aristidesparallax@y...> wrote:
> > HelloLiang,
> >
> > > I'm looking for a
> > > command or some way to skip a few lines in the code if certain
> > > condition is satisfied. i.e.
> > >
> > > IF freq = 0 THEN ?(skip the following two lines)
> > > IF freq > 2000 AND freq <3500 THEN do_this
> > > IF freq > 4000 AND freq <6000 THEN do_that
> > >
> >
> > Like this?
> >
> > IF freq = 0 THEN Skip_Lines ' Jumps to the label Skip_Lines
> > ' when
> condition is
> > true.
> > IF freq > 2000 AND freq <3500 THEN do_this
> > IF freq > 4000 AND freq <6000 THEN do_that
> > Skip_Lines:
> >
> > Saludos,
> > Aristides Alvarez
> > International Education Program Developer
> > aalvarez@p...
> > Parallax, Inc. www.parallax.com
> > California, USA
following?
if freq > 0 and freq < 2000
if freq > 3500 and freq < 4000
if freq > 6000
My assumption is the frequency in your application is generated by a motor or
some sort, and if so, will the stamp ever encounter the frequency other than
the range of your three distinct if conditions?
In a message dated 2/4/2004 10:53:34 PM Pacific Standard Time,
lxing@c... writes:
I'm stuck when trying to write a program in BS2, I'm looking for a
command or some way to skip a few lines in the code if certain
condition is satisfied. i.e.
IF freq = 0 THEN ?(skip the following two lines)
IF freq > 2000 AND freq <3500 THEN do_this
IF freq > 4000 AND freq <6000 THEN do_that
Anyone got any ideas, please help me.
[noparse][[/noparse]Non-text portions of this message have been removed]
IF (freq > 2000) AND (freq < 3500) THEN
' do this code
ELSIF (freq > 4000) and (freq < 6000) THEN
' do that code
ELSE
' else code
ENDIF
You need version 2.1 of the editor to do this.
-- Jon Williams
-- Applications Engineer, Parallax
-- Dallas Office
Original Message
From: Liang Xing [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=tpZhKz0NwKJMp7q0mvVB0OdlfZlHpvqMvMo8jRb3coOO_pzgs-WCn66mMiYTgnkDyoEO8Z4]lxing@c...[/url
Sent: Wednesday, February 04, 2004 9:55 PM
To: basicstamps@yahoogroups.com
Subject: [noparse][[/noparse]basicstamps] BS2sx skip line
Hello,
I'm stuck when trying to write a program in BS2, I'm looking for a
command or some way to skip a few lines in the code if certain
condition is satisfied. i.e.
IF freq = 0 THEN ?(skip the following two lines)
IF freq > 2000 AND freq <3500 THEN do_this
IF freq > 4000 AND freq <6000 THEN do_that
Anyone got any ideas, please help me.
Thanks
of using nested IF statements. Parens added for clarity and to insure that
strict left to right interpretation. (I'm a long time programmer but new to
PBASIC so my syntax may not be correct but the point is valid.) See help
text from editor window, Case structure is not in my manual.
SELECT freq
CASE (freq<=2000) your code said=0, if values 0 to 2000 exist use
this
,,, code or no code
CASE ((freq>2000) and (freq<3500))
,,,do this
CASE ((freq>4000) AND (freq<600))
,,,do that
CASE ELSE
,,,do 6000 & over or nothing
ENDSELECT
Jay Hocott
"Good is better than evil because it's nicer."
Mammy Yokum
>
>
> In a message dated 2/4/2004 10:53:34 PM Pacific Standard Time,
> lxing@c... writes:
> I'm stuck when trying to write a program in BS2, I'm looking for a
> command or some way to skip a few lines in the code if certain
> condition is satisfied. i.e.
>
> IF freq = 0 THEN ?(skip the following two lines)
> IF freq > 2000 AND freq <3500 THEN do_this
> IF freq > 4000 AND freq <6000 THEN do_that
>
> Anyone got any ideas, please help me.
>
>
> [noparse][[/noparse]Non-text portions of this message have been removed]
>
>
>
> To UNSUBSCRIBE, just send mail to:
> basicstamps-unsubscribe@yahoogroups.com
> from the same email address that you subscribed. Text in the Subject and
Body of the message will be ignored.
>
> Yahoo! Groups Links
>
>
>
>
>
>
> This message has been processed by Firetrust Benign.
SELECT freq
CASE < 2000
' freq is less than 2000
CASE 2000 TO 3500
' do something else
CASE 4000 TO 6000
' do somthing else altogether
CASE ELSE
' freq is greater than 6000
ENDSELECT
-- Jon Williams
-- Applications Engineer, Parallax
-- Dallas Office
Original Message
From: Jay Website [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=Fz4ZWbJxSAKrOs5lmUsq3fHdvmPWdY2JPQCUgeRgbgZ0jtb4ONkskDrhNOYN2_5VM5qZhJac7zB9]jay@h...[/url
Sent: Thursday, February 05, 2004 10:17 AM
To: basicstamps@yahoogroups.com
Subject: Re: [noparse][[/noparse]basicstamps] BS2sx skip line
The CASE structure was devised to handle complex conditions clearly
instead of using nested IF statements. Parens added for clarity and to
insure that strict left to right interpretation. (I'm a long time
programmer but new to PBASIC so my syntax may not be correct but the
point is valid.) See help text from editor window, Case structure is
not in my manual.
SELECT freq
CASE (freq<=2000) your code said=0, if values 0 to 2000 exist use
this
,,, code or no code
CASE ((freq>2000) and (freq<3500))
,,,do this
CASE ((freq>4000) AND (freq<600))
,,,do that
CASE ELSE
,,,do 6000 & over or nothing
ENDSELECT
Jay Hocott
"Good is better than evil because it's
nicer." Mammy Yokum
>
>
> In a message dated 2/4/2004 10:53:34 PM Pacific Standard Time,
> lxing@c... writes: I'm stuck when trying to write a program in
> BS2, I'm looking for a command or some way to skip a few lines in the
> code if certain condition is satisfied. i.e.
>
> IF freq = 0 THEN ?(skip the following two lines)
> IF freq > 2000 AND freq <3500 THEN do_this
> IF freq > 4000 AND freq <6000 THEN do_that
>
> Anyone got any ideas, please help me.
With your math, 'FREQ' will equal 0 very seldom.
"If FREQ < 2000 ... " might do more what you want.
Checking a calculated number like FREQ
for equality with a fixed value is generally
not a good idea -- checking it for above
and/or below the fixed value works better.
--- In basicstamps@yahoogroups.com, "Liang Xing" <lxing@c...> wrote:
> Thanks for the reply, I have tried that, however, the only problem
> is the servo turns very slow when doing the "Go_straight,
> Correct_right,Correct_left,Go_straight",i dont know why, the servo
> does fine in another code. like in the following codes.
>
>
>
> 'Main program
>
> Loop:
> Left_sensor = IN1 'Monitor state of the pins here
> Right_sensor = IN0
> PULSIN FreqPin, 0, pHigh ' get high portion of input
> PULSIN FreqPin, 1, pLow ' get low portion of input
> period = (pHigh + pLow) */ Convert ' calculate cycle width in
> uSecs
> freq = 50000 / period * 20 ' calculate frequency
>
> IF freq = 0 THEN Normal
> IF freq > 2000 AND freq <3500 THEN Turn_right
> IF freq > 4000 AND freq <6000 THEN Turn_left
>
> Normal:
> IF Left_sensor = 0 AND Right_sensor = 0 THEN Go_straight
> IF Left_sensor = 1 AND Right_sensor = 0 THEN Correct_right
> IF Left_sensor = 0 AND Right_sensor = 1 THEN Correct_left
> IF Left_sensor = 1 AND Right_sensor = 1 THEN Go_straight
>
> 'Sub routines
> Go_straight:
> PULSOUT 2, 1500 'Servomotor is 90 degree (neutral position)
> 'PAUSE 5
> GOTO Loop
>
> Correct_right:
> PULSOUT 2, 2100 'some small angle to the right
> 'PAUSE 5
> GOTO Loop
>
> Correct_left:
> PULSOUT 2, 800 'some small angle to the left
> 'PAUSE 5
> GOTO Loop
>
> Turn_right:
> FOR reps = 0 TO 190
> PULSOUT 2, 2100
> PAUSE 10
> NEXT
>
> FOR reps2 = 0 TO 190
> PULSOUT 2, 800
> PAUSE 10
> NEXT
>
> GOTO Loop
>
> Turn_left:
> FOR reps = 0 TO 190
> PULSOUT 2, 800
> PAUSE 10
> NEXT
>
> FOR reps2 = 0 TO 190
> PULSOUT 2, 2100
> PAUSE 10
> NEXT
>
> GOTO Loop
>
> --- In basicstamps@yahoogroups.com, "Aristides Alvarez"
> <aristidesparallax@y...> wrote:
> > HelloLiang,
> >
> > > I'm looking for a
> > > command or some way to skip a few lines in the code if certain
> > > condition is satisfied. i.e.
> > >
> > > IF freq = 0 THEN ?(skip the following two lines)
> > > IF freq > 2000 AND freq <3500 THEN do_this
> > > IF freq > 4000 AND freq <6000 THEN do_that
> > >
> >
> > Like this?
> >
> > IF freq = 0 THEN Skip_Lines ' Jumps to the label Skip_Lines
> > ' when
> condition is
> > true.
> > IF freq > 2000 AND freq <3500 THEN do_this
> > IF freq > 4000 AND freq <6000 THEN do_that
> > Skip_Lines:
> >
> > Saludos,
> > Aristides Alvarez
> > International Education Program Developer
> > aalvarez@p...
> > Parallax, Inc. www.parallax.com
> > California, USA