Shop OBEX P1 Docs P2 Docs Learn Events
HELP!! I want to do an if......else loop — Parallax Forums

HELP!! I want to do an if......else loop

ArchiverArchiver Posts: 46,084
edited 2003-02-26 20:25 in General Discussion
Hi.
This is my problem. I have four different instruments from which my
stamp can collect readings. I want my programme to constantly read in
rainfall and to only read in from another instrument unless
instructed to by a command using the SERIN command.
However, how do I do this? At the moment I get the programme to count
rainfall for 10 seconds, and then using the following instruction, it
checks if a command has come in from Visual Basic

SERIN RX\CTS, Baud, [noparse][[/noparse]cmd]
if (cmd = 120) Then TESTING 'x
if (cmd = 114) Then TX_Rain 'r
if (cmd = 097) Then SPEED 'a

However if no command has been received, I want to return to Main.
Is there any way to do some sort of if...else loop in PBASIC?
I am using a 2SX (very similiar to a BS2 but faster).

Thank-you so much for any help!

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2003-02-26 19:32
    1. PBasic only does 'IF xxx THEN <goto Dest Label>'
    So, if you want IF/THEN/ELSE, do like:
    IF (CMD <> 120) THEN Skip1
    'ELSE
    GOTO Testing
    Skip1:
    IF (CMD <> 114) THEN Skip2
    'ELSE
    GOTO TX_Rain
    Skip2:

    Etcetera.
    Or, PBasic 2.5, currently in Beta, has a true
    If-Then-Else, AND a true IF-Then-Gosub.
    Get it from their Website.

    --- In basicstamps@yahoogroups.com, "Caryatnid <e99bf0e8@s...>"
    <e99bf0e8@s...> wrote:
    > Hi.
    > This is my problem. I have four different instruments from which my
    > stamp can collect readings. I want my programme to constantly read
    in
    > rainfall and to only read in from another instrument unless
    > instructed to by a command using the SERIN command.
    > However, how do I do this? At the moment I get the programme to
    count
    > rainfall for 10 seconds, and then using the following instruction,
    it
    > checks if a command has come in from Visual Basic
    >
    > SERIN RX\CTS, Baud, [noparse][[/noparse]cmd]
    > if (cmd = 120) Then TESTING 'x
    > if (cmd = 114) Then TX_Rain 'r
    > if (cmd = 097) Then SPEED 'a
    >
    > However if no command has been received, I want to return to Main.
    > Is there any way to do some sort of if...else loop in PBASIC?
    > I am using a 2SX (very similiar to a BS2 but faster).
    >
    > Thank-you so much for any help!
  • ArchiverArchiver Posts: 46,084
    edited 2003-02-26 19:40
    Thanks Allan, for your help and ideas. However I think I didn't
    explain myself properly in the first place. Suppose I don't get a
    command at all from VB (as would be happening most of the time), then
    I want to continue counting the rain (goto Main).


    --- In basicstamps@yahoogroups.com, "Allan Lane <allan.lane@h...>"
    <allan.lane@h...> wrote:
    > 1. PBasic only does 'IF xxx THEN <goto Dest Label>'
    > So, if you want IF/THEN/ELSE, do like:
    > IF (CMD <> 120) THEN Skip1
    > 'ELSE
    > GOTO Testing
    > Skip1:
    > IF (CMD <> 114) THEN Skip2
    > 'ELSE
    > GOTO TX_Rain
    > Skip2:
    >
    > Etcetera.
    > Or, PBasic 2.5, currently in Beta, has a true
    > If-Then-Else, AND a true IF-Then-Gosub.
    > Get it from their Website.
    >
    > --- In basicstamps@yahoogroups.com, "Caryatnid <e99bf0e8@s...>"
    > <e99bf0e8@s...> wrote:
    > > Hi.
    > > This is my problem. I have four different instruments from which
    my
    > > stamp can collect readings. I want my programme to constantly
    read
    > in
    > > rainfall and to only read in from another instrument unless
    > > instructed to by a command using the SERIN command.
    > > However, how do I do this? At the moment I get the programme to
    > count
    > > rainfall for 10 seconds, and then using the following
    instruction,
    > it
    > > checks if a command has come in from Visual Basic
    > >
    > > SERIN RX\CTS, Baud, [noparse][[/noparse]cmd]
    > > if (cmd = 120) Then TESTING 'x
    > > if (cmd = 114) Then TX_Rain 'r
    > > if (cmd = 097) Then SPEED 'a
    > >
    > > However if no command has been received, I want to return to
    Main.
    > > Is there any way to do some sort of if...else loop in PBASIC?
    > > I am using a 2SX (very similiar to a BS2 but faster).
    > >
    > > Thank-you so much for any help!
  • ArchiverArchiver Posts: 46,084
    edited 2003-02-26 19:44
    Hi Allan, sorry to bother you again but I've been on the Parallax
    site and can't find this PBASIC 2.5 that you talk about. Can you tell
    me where I can find it please? Thanks again.

    --- In basicstamps@yahoogroups.com, "Allan Lane <allan.lane@h...>"
    <allan.lane@h...> wrote:
    > 1. PBasic only does 'IF xxx THEN <goto Dest Label>'
    > So, if you want IF/THEN/ELSE, do like:
    > IF (CMD <> 120) THEN Skip1
    > 'ELSE
    > GOTO Testing
    > Skip1:
    > IF (CMD <> 114) THEN Skip2
    > 'ELSE
    > GOTO TX_Rain
    > Skip2:
    >
    > Etcetera.
    > Or, PBasic 2.5, currently in Beta, has a true
    > If-Then-Else, AND a true IF-Then-Gosub.
    > Get it from their Website.
    >
    > --- In basicstamps@yahoogroups.com, "Caryatnid <e99bf0e8@s...>"
    > <e99bf0e8@s...> wrote:
    > > Hi.
    > > This is my problem. I have four different instruments from which
    my
    > > stamp can collect readings. I want my programme to constantly
    read
    > in
    > > rainfall and to only read in from another instrument unless
    > > instructed to by a command using the SERIN command.
    > > However, how do I do this? At the moment I get the programme to
    > count
    > > rainfall for 10 seconds, and then using the following
    instruction,
    > it
    > > checks if a command has come in from Visual Basic
    > >
    > > SERIN RX\CTS, Baud, [noparse][[/noparse]cmd]
    > > if (cmd = 120) Then TESTING 'x
    > > if (cmd = 114) Then TX_Rain 'r
    > > if (cmd = 097) Then SPEED 'a
    > >
    > > However if no command has been received, I want to return to
    Main.
    > > Is there any way to do some sort of if...else loop in PBASIC?
    > > I am using a 2SX (very similiar to a BS2 but faster).
    > >
    > > Thank-you so much for any help!
  • ArchiverArchiver Posts: 46,084
    edited 2003-02-26 19:47
    Hello,

    PBASIC 2.5 in Beta 1 form is in the Downloads section
    http://www.parallax.com/html_pages/downloads/software/pbasic_2_5.asp

    Or use the horizontal menu, highlight "Downloads" then click on "BASIC
    Stamp Software"

    Erik Wood
    ewood@p...
    Parallax, Inc.
    599 Menlo Dr., Suite #100
    Rocklin, CA 95765
    (916) 624-8333
    www.parallax.com


    Original Message
    From: Caryatnid <e99bf0e8@s...>
    [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=VveI4XAvaPT0uVkjUuHF6BH62rETZv_nU2I1IvZkDhBtw_nnoicxkAkWvO9xXT2HylIOErlt1Hrya-AISg]e99bf0e8@s...[/url
    Sent: Wednesday, February 26, 2003 11:45 AM
    To: basicstamps@yahoogroups.com
    Subject: [noparse][[/noparse]basicstamps] Re: HELP!! I want to do an if......else loop


    Hi Allan, sorry to bother you again but I've been on the Parallax
    site and can't find this PBASIC 2.5 that you talk about. Can you tell
    me where I can find it please? Thanks again.

    --- In basicstamps@yahoogroups.com, "Allan Lane <allan.lane@h...>"
    <allan.lane@h...> wrote:
    > 1. PBasic only does 'IF xxx THEN <goto Dest Label>'
    > So, if you want IF/THEN/ELSE, do like:
    > IF (CMD <> 120) THEN Skip1
    > 'ELSE
    > GOTO Testing
    > Skip1:
    > IF (CMD <> 114) THEN Skip2
    > 'ELSE
    > GOTO TX_Rain
    > Skip2:
    >
    > Etcetera.
    > Or, PBasic 2.5, currently in Beta, has a true
    > If-Then-Else, AND a true IF-Then-Gosub.
    > Get it from their Website.
    >
    > --- In basicstamps@yahoogroups.com, "Caryatnid <e99bf0e8@s...>"
    > <e99bf0e8@s...> wrote:
    > > Hi.
    > > This is my problem. I have four different instruments from which
    my
    > > stamp can collect readings. I want my programme to constantly
    read
    > in
    > > rainfall and to only read in from another instrument unless
    > > instructed to by a command using the SERIN command.
    > > However, how do I do this? At the moment I get the programme to
    > count
    > > rainfall for 10 seconds, and then using the following
    instruction,
    > it
    > > checks if a command has come in from Visual Basic
    > >
    > > SERIN RX\CTS, Baud, [noparse][[/noparse]cmd]
    > > if (cmd = 120) Then TESTING 'x
    > > if (cmd = 114) Then TX_Rain 'r
    > > if (cmd = 097) Then SPEED 'a
    > >
    > > However if no command has been received, I want to return to
    Main.
    > > Is there any way to do some sort of if...else loop in PBASIC?
    > > I am using a 2SX (very similiar to a BS2 but faster).
    > >
    > > Thank-you so much for any help!


    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.


    Your use of Yahoo! Groups is subject to
    http://docs.yahoo.com/info/terms/
  • ArchiverArchiver Posts: 46,084
    edited 2003-02-26 19:53
    there is a timeout facility on the serin command:

    serin Rpin, Baud, Timeout, Tlabel, [noparse][[/noparse]data]

    Timeout is the time to wait for data (in 400us units on the BS2sx)
    Tlabel is a program location to jump to in case of a timeout.
    See the manual pages 273 ff. for details.
    Note that the stamp is not able to receive anything while doing
    anything else and there is no input buffering (can be added
    easily however).

    hope this helps
    Adrian
  • ArchiverArchiver Posts: 46,084
    edited 2003-02-26 19:59
    SERIN has a timeout, Label option:
    SERIN RX\CTS, Baud, 10000, Timeout, [noparse][[/noparse]cmd]
    .
    .
    Timeout:
    ' Come here if no data in 10,000 mSecs (10 secs)


    http://www.parallax.com/html_pages/downloads/software/software_basic_s
    tamp.asp
    (If above link gets split, unsplit it in Notepad)
    I meant the "Basic Stamp Windows 2.0 (Beta)" editor,
    with IF-THEN-ELSE...


    --- In basicstamps@yahoogroups.com, "Caryatnid <e99bf0e8@s...>"
    <e99bf0e8@s...> wrote:
    > Hi Allan, sorry to bother you again but I've been on the Parallax
    > site and can't find this PBASIC 2.5 that you talk about. Can you
    tell
    > me where I can find it please? Thanks again.
    >
    > --- In basicstamps@yahoogroups.com, "Allan Lane <allan.lane@h...>"
    > <allan.lane@h...> wrote:
    > > 1. PBasic only does 'IF xxx THEN <goto Dest Label>'
    > > So, if you want IF/THEN/ELSE, do like:
    > > IF (CMD <> 120) THEN Skip1
    > > 'ELSE
    > > GOTO Testing
    > > Skip1:
    > > IF (CMD <> 114) THEN Skip2
    > > 'ELSE
    > > GOTO TX_Rain
    > > Skip2:
    > >
    > > Etcetera.
    > > Or, PBasic 2.5, currently in Beta, has a true
    > > If-Then-Else, AND a true IF-Then-Gosub.
    > > Get it from their Website.
    > >
    > > --- In basicstamps@yahoogroups.com, "Caryatnid <e99bf0e8@s...>"
    > > <e99bf0e8@s...> wrote:
    > > > Hi.
    > > > This is my problem. I have four different instruments from
    which
    > my
    > > > stamp can collect readings. I want my programme to constantly
    > read
    > > in
    > > > rainfall and to only read in from another instrument unless
    > > > instructed to by a command using the SERIN command.
    > > > However, how do I do this? At the moment I get the programme to
    > > count
    > > > rainfall for 10 seconds, and then using the following
    > instruction,
    > > it
    > > > checks if a command has come in from Visual Basic
    > > >
    > > > SERIN RX\CTS, Baud, [noparse][[/noparse]cmd]
    > > > if (cmd = 120) Then TESTING 'x
    > > > if (cmd = 114) Then TX_Rain 'r
    > > > if (cmd = 097) Then SPEED 'a
    > > >
    > > > However if no command has been received, I want to return to
    > Main.
    > > > Is there any way to do some sort of if...else loop in PBASIC?
    > > > I am using a 2SX (very similiar to a BS2 but faster).
    > > >
    > > > Thank-you so much for any help!
  • ArchiverArchiver Posts: 46,084
    edited 2003-02-26 20:25
    Thanks so much to Adrian and Allan, your suggestions seem just to be
    what I'm looking for. Sorry for being unclear at first. Thanks,
    Caryatnid.
Sign In or Register to comment.