Shop OBEX P1 Docs P2 Docs Learn Events
serin? — Parallax Forums

serin?

HwardHward Posts: 8
edited 2006-01-04 21:19 in BASIC Stamp
Trying to learn how to use serin,·· I have a little vb program writen that is just sending out a number when some thing is clicked.· Right now I am just trying to recieve the serial data on my bs2 and debug it but am not having any luck really·· I know its hooked up right.·· I have gotten it to work with this code.

loop:
SERIN 1,16572,[noparse][[/noparse]WAIT ("1")]
DEBUG "1"
PAUSE 500
DEBUG CLS
GOTO loop


But I don't want it to really wait just debugs what ever number comes in

·

Comments

  • Tom WalkerTom Walker Posts: 509
    edited 2006-01-04 19:48
    You're close...but you need to tell the SERIN command what to do with the data that it "sees" on the serial line. You don't need the WAIT, but you do need a variable to put the data into. Have another look at the SERIN command reference. This is not a cop-out, but I find that it "sticks" better when you look at the reference.

    Once you have the data in a variable (defined to be the right size, of course), you can display it with the DEBUG command. Right now, you are just displaying the literal "1", waiting for half of a second, clearing the screen and repeating the process.

    Hope this helps.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Truly Understand the Fundamentals and the Path will be so much easier...
  • HwardHward Posts: 8
    edited 2006-01-04 20:33
    this seems to be working······· anyone see any problems with it

    serData·· VAR··· Word
    loop:
    SERIN 1,16572,[noparse][[/noparse]serData]
    IF serData = "1" THEN MoveUp
    IF serData = "2" THEN MoveDown
    IF serData = "3" THEN MoveRight
    IF serData = "4" THEN MoveLeft
    GOTO loop
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-01-04 21:19
    There is a *problem* in that you're using "loop" as a label and that is a PBASIC 2.5 keyword.· Here's an updated version that uses PBASIC 2.5 syntax and is a little cleaner, and does error trapping:

    Main:
    · DO
    ··· DO
    ···· ·SERIN Sin, Baud, [noparse][[/noparse]cmd]
    ···· ·LOOKDOWN cmd, [noparse][[/noparse]"1234"], cmd
    ····LOOP UNTIL (cmd <= 3)
    ··· ON cmd GOSUB Move_Up, Move_Dn, Move_Rt, Move_Lf
    · LOOP

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
Sign In or Register to comment.