View Full Version : serin?
01-05-2006, 02:41 AM
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.
SERIN 1,16572,[WAIT ("1")]
But I don't want it to really wait just debugs what ever number comes in
01-05-2006, 03:48 AM
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...
01-05-2006, 04:33 AM
this seems to be working······· anyone see any problems with it
serData·· VAR··· Word
IF serData = "1" THEN MoveUp
IF serData = "2" THEN MoveDown
IF serData = "3" THEN MoveRight
IF serData = "4" THEN MoveLeft
01-05-2006, 05:19 AM
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:
···· ·SERIN Sin, Baud, [cmd]
···· ·LOOKDOWN cmd, ["1234"], cmd
····LOOP UNTIL (cmd <= 3)
··· ON cmd GOSUB Move_Up, Move_Dn, Move_Rt, Move_Lf
Applications Engineer, Parallax