Shop OBEX P1 Docs P2 Docs Learn Events
BS and LCD how do I? — Parallax Forums

BS and LCD how do I?

jdoleckijdolecki Posts: 726
edited 2010-08-12 14:53 in BASIC Stamp
I want my Serout commant to reference a place were I would have Foward, Backwards, Left ,Right stored.

How do I move Foward,backwards , left and right in and out of that place?
Do i store it in a Var called Word?
What would I replace "Running Mode" with in this line?
SEROUT 15,n9600,[" Running Mode!"] ' Print message. to tell it go look in the storage spot.


Here is what I have

thanks


' {$STAMP BS2}
' {$PBASIC 2.5}

N9600 CON $4054 ' Baudmode-9600 bps inverted. Use $40F0 for BS2-SX.
I CON 254 ' Instruction prefix value.
CLR CON 1 ' LCD clear-screen instruction.


DO
IF (IN12 = 0) THEN
GOSUB Battery
ELSEIF (IN12 = 1) THEN
GOSUB Running
ENDIF
LOOP

GOSUB Running
GOSUB Battery
END

Running:
PAUSE 1000
SEROUT 15,n9600,[I,CLR] ' Clear the LCD screen.
PAUSE 1
SEROUT 15,n9600,[" Running Mode!"] ' Print message.
RETURN

Battery:
PAUSE 1000
SEROUT 15,n9600,[I,CLR] ' Clear the LCD screen.
PAUSE 1
SEROUT 15,n9600,["- Battery Life +"] ' Print message.
RETURN

Comments

  • FranklinFranklin Posts: 4,747
    edited 2010-08-12 13:07
    Could you supply more info? what you have now just displays text when you press a button? just add more if/elsifs for the other phrases. If this is not what you want explain better what it is you want.
  • jdoleckijdolecki Posts: 726
    edited 2010-08-12 13:14
    When Im in running I want to display foward, backwards, left or right below the "running mode"
    depending on what my vehicle is doing.

    in the serout command when is says to display "Running mode" i want to access a varable instead

    What do i replace "running mode" with to access a varabale that stores the words foward,back,left, right?

    SEROUT 15,n9600,[" Running Mode!"] ' Print message.

    does that sound better?
  • rixterrixter Posts: 95
    edited 2010-08-12 14:31
    Dr Evil,

    You can't store those strings in a Word variable. The best you could do would be to use an array or read in each letter in DATA statements. Too much hassle. Franklin's suggestion is probably the easiest to implement especially since you have limited and short list of possible scenarios. So you would modify the "running:" section to include four conditionals (IF , ELSEIF), for whatever in your project is deeming the movements FOWARD, BACKWARD, LEFT or RIGHT and have the appropriate string printed out. That is to say that you'd ultimately have four SEROUT commands with the four possible strings instead of using a variable. If you are monitoring buttons to determine motion direction, be sure to handle (or understand at least), the possibility of no buttons being pressed or multiple buttons being pressed simultaneously.

    Rick
  • velociostrichvelociostrich Posts: 40
    edited 2010-08-12 14:53
    Showing what your vehicle (whatever it might be) is doing can be accomplished in many ways, but perhaps the easiest would entail the use of the SELECT...CASE command. You simply cannot store messages longer than two characters in a word -- each character normally requires one byte (unless you use some trickery), and a word is only two bytes. Furthermore, the longest message you could store in RAM would be 26 characters as that is all the memory avaliable to the BASIC Stamp, though doing so would mean that you could not have any other variables. Rather, using the SELECT...CASE command as mentioned before would require that you only have one variable that would indicate the vehicle's current state, which would then be compared to constants enumerating those states. That is, for every state your vehicle could be in (or just those you would like to display), you would define a constant with a unique value. The other method for displaying what state your vehicle is in would be to only update the display when that state changes, in the logic that would change the vehicle's state.

    Anyways, using the SELECT...CASE statement would look something like this:
    moveForward CON 0
    moveBackward CON 1
    turnLeft CON 2
    turnRight CON 3
    
    runningMode VAR Nib
    
    ' Code omitted
    
    SELECT runningMode
      CASE moveForward
        SEROUT 15, n9600, ["Moving forward"]
      CASE moveBackward
        SEROUT 15, n9600, ["Moving backward"]
      CASE turnLeft
        SEROUT 15, n9600, ["Turning left"]
      CASE turnRight
        SEROUT 15, n9600, ["Turning right"]
    ENDSELECT
    

    The second method, where you would only update the display when the vehicle's state changed would look something like this:
    True CON 1
    False CON 0
    
    hitWall VAR Bit
    
    ' Code omitted
    
    IF hitWall = True THEN
      ' Indicate that the vehicle has switched to turning left
      SEROUT 15, n9600, ["Turning left"]
      ' Actually turn left
      GOSUB turnLeft
    ENDIF
    

    Note that in either of these examples, I've omitted whatever other logic you might want to write, so you can't just copy and paste these into your code and expect them to work. I would suggest trying to get a better understanding of what you're trying to do and what the code I've written does if you don't already know.
Sign In or Register to comment.