Shop OBEX P1 Docs P2 Docs Learn Events
Newbie, VB to BS2 — Parallax Forums

Newbie, VB to BS2

ArchiverArchiver Posts: 46,084
edited 2001-04-08 15:52 in General Discussion
On 7 Apr 01 at 3:55, furryspinto@y... wrote:

...
> main:
> kts var byte
> serin 16,16468,[noparse][[/noparse]kts]
> if kts <79 then ORANGEono
> if kts >80 then GREENono
> if kts >120 then REDono

Third IF is never executed since second IF already caught these...

Try this instead:

IF kts > 120 THEN REDono
IF kts < 79 THEN ORANGEono
GREENono:
...


Or, the Tracy Allen "We don't need no stinking spaghetti code"
solution:

BRANCH kts/40,[noparse][[/noparse] ORANGEono, ORANGEono, GREENono, REDono... ]


Regards,

Steve

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2001-04-07 04:55
    Evening all,

    I've searched through as much of the group and found a couple of
    things that I might try. Here's my prob.

    I have written a small terminal program in VB6, eventually it will be
    used as the GUI for the user. I am using it currently to test SERIN,
    SEROUT, (experimenting).

    I would like to control the state of 3 LED's depending on the input
    from the user. The bs2 code is is below. The circuit works, and
    communication is established with PC/BS2.

    If the user enters a number between 0 & 79 no problem orange LED goes
    on.

    Now the peoblem starts, the green LED does not go on unless the
    number enterd is greater than 100, and the Red LED will never go on
    regardless. I can switch back and forth between the Orange and Green
    LED but not with the numbers I prescribed. My original thinking was
    that maybe BS2 saw the number as Binary, but 100 is not Binary for 80.

    Am I way off track here? Anyhelp getting me pointed in the right
    direction is appreciated, don't worry about offending me if my BS2
    code is real sloppy, I'm just new to it ;-)

    Thanks in advance.
    output 0 'sets pin 5 P0 as output
    output 1 'sets pin 6 P1 as output
    output 2 'sets pin 7 P2 as output

    goto LEDoff

    main:
    kts var byte
    serin 16,16468,[noparse][[/noparse]kts]
    if kts <79 then ORANGEono
    if kts >80 then GREENono
    if kts >120 then REDono

    LEDoff:
    out0=1
    out1=1
    out2=1
    goto main

    GREENono:
    out0=0
    out1=1
    out2=1
    goto main

    REDono:
    out0=1
    out1=0
    out2=1
    goto main

    ORANGEono:
    out0=1
    out1=1
    out2=0
    goto main
  • ArchiverArchiver Posts: 46,084
    edited 2001-04-07 13:23
    Chris-

    Jeff explained it. The kts/40 just takes advantage of the multiples
    of 40 inherent in your specified cutoff points, plus how the integer
    divide works, to yield a branch index. With some thought, you can
    often use techniques like this to write "cleaner" code and minimize
    code space requirements.


    Regards,

    Steve

    On 8 Apr 01 at 7:36, Chris Anderson wrote:

    > Hello Steve or Tracy, can you give a quick explanation of the
    > "kts/40" below, does it simply make branch segments of 40, such as
    > ,0 to 40, 41 to 80, 81 to 120, >120,
    >
    >
    > BRANCH kts/40,[noparse][[/noparse] ORANGEono, ORANGEono, GREENono, REDono... ]
  • ArchiverArchiver Posts: 46,084
    edited 2001-04-07 19:39
    You might try a simpler program to start out, to test the interface:

    high 0 'sets pin 5 P0 as output, led off
    high 1 'sets pin 6 P1 as output, "
    high 2 'sets pin 7 P2 as output, "

    main:
    kts var byte
    serin 16,16468,[noparse][[/noparse]kts] ' this is the BS2 baud rate 9600
    outL=~kts ' makes the low 3 bits follow the ascii codes
    ' ~ inverts all bits
    goto main

    Then when you type characters "A", "B", "C" etc. the leds should
    light up in a binary sequence.

    >I have written a small terminal program in VB6, eventually it will be
    >used as the GUI for the user. I am using it currently to test SERIN,
    >SEROUT, (experimenting).
    >I would like to control the state of 3 LED's depending on the input
    >from the user.
    >snip...
    >
    >output 0 'sets pin 5 P0 as output
    >output 1 'sets pin 6 P1 as output
    >output 2 'sets pin 7 P2 as output
    >
    >goto LEDoff
    >
    >main:
    >kts var byte
    >serin 16,16468,[noparse][[/noparse]kts]
    >if kts <79 then ORANGEono
    >if kts >80 then GREENono
    >if kts >120 then REDono
    >
    >LEDoff:
    > out0=1
    > out1=1
    > out2=1
    >goto main
    >
    >GREENono:
    > out0=0
    > out1=1
    > out2=1
    >goto main
    >
    >REDono:
    > out0=1
    > out1=0
    > out2=1
    >goto main
    >
    >ORANGEono:
    > out0=1
    > out1=1
    > out2=0
    >goto main
    >
    >
    >
    >
    >
    >Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
  • ArchiverArchiver Posts: 46,084
    edited 2001-04-08 00:36
    Hello Steve or Tracy, can you give a quick explanation of the "kts/40"
    below, does it simply make branch segments of 40, such as ,0 to 40, 41 to
    80, 81 to 120, >120,


    BRANCH kts/40,[noparse][[/noparse] ORANGEono, ORANGEono, GREENono, REDono... ]

    regards, Chris
  • ArchiverArchiver Posts: 46,084
    edited 2001-04-08 00:52
    Chris,

    " BRANCH kts/40,[noparse][[/noparse] ORANGEono, ORANGEono, GREENono, REDono... ]"

    The objects within the brackets are separated by commas and are addressed
    as 0,1,2,3, etc. The "Branch kts/40" divides kts by forty. So if kts = 80
    then it will be divided by forty =2 =GREENono. If kts=39 then a division by
    40 will = less than one which the stamp interprets as zero (ORANGEono)

    Hope this helps

    Jeff
  • ArchiverArchiver Posts: 46,084
    edited 2001-04-08 03:34
    Thanks, its clear now, its simply the divide "/" function, not a special
    operator or anything fancy.
    Chris
    Original Message
    From: Jeff Mitchell <EL-JEFE@P...>
    To: <basicstamps@yahoogroups.com>
    Sent: Sunday, April 08, 2001 7:52 AM
    Subject: Re: [noparse][[/noparse]basicstamps] Newbie, VB to BS2


    > Chris,
    >
    > " BRANCH kts/40,[noparse][[/noparse] ORANGEono, ORANGEono, GREENono, REDono... ]"
    >
    > The objects within the brackets are separated by commas and are
    addressed
    > as 0,1,2,3, etc. The "Branch kts/40" divides kts by forty. So if kts = 80
    > then it will be divided by forty =2 =GREENono. If kts=39 then a division
    by
    > 40 will = less than one which the stamp interprets as zero (ORANGEono)
    >
    > Hope this helps
    >
    > Jeff
    >
    >
    >
    >
    >
    > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2001-04-08 15:52
    Wow,

    Thanks to everyone that took the time to look at my question, I
    really learned a great deal from all of your suggestions!

    Thanks,

    Andy
Sign In or Register to comment.