Shop OBEX P1 Docs P2 Docs Learn Events
Basic Help needed! — Parallax Forums

Basic Help needed!

martijnmartijn Posts: 6
edited 2008-01-27 20:04 in BASIC Stamp
I'm just beginning to learn the basics of programming the basic stamp 2.
My first testprogram is working great, although the second is not working, i hope someone can help me with this one!

First the program that works:

' {$STAMP BS2}
' {$PBASIC 2.5}
' {$PORT COM13}
inFromSerialVar VAR Byte
Main:
· SERIN 7, 16468, [noparse][[/noparse]inFromSerialVar]
· IF inFromSerialVar THEN
··· GOSUB LightA:
· ENDIF
GOTO main
LightA:
HIGH 8
PAUSE 1000
LOW 8
RETURN

Now i want the code to check a incomming var like "A"(ASCII=65) and "B" (ASCII=66) then the function lightA or lightB should follow.

but i cant get the next code working:
' {$STAMP BS2}
' {$PBASIC 2.5}
' {$PORT COM13}
serData·· VAR···· Byte

Main:

· SEROUT 6, 16468, [noparse][[/noparse]"A"]
· SERIN 1, 16780, [noparse][[/noparse]WAIT("123"), DEC serData]
· DEBUG ? serData
· IF serData THEN
······ GOSUB LichtAan
· ENDIF
GOTO main
LichtAan:
HIGH 8
PAUSE 1000
LOW 8
RETURN


now the serial input is correct ( i monitor it with a port monitor app)·<!--StartFragment -->
the input now is correct:·A123AB (ASCII 41 31 32 33 41 42)·

i hope someone will help me.
Martijn

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-01-26 21:38
    When you have "SERIN ...,...,[noparse][[/noparse]WAIT ..., DEC serData]", you are asking PBasic to wait for "123", then look for a sequence of digits and to return the numeric value of the digits. If you just put "WAIT ..., serData" and leave out the "DEC", PBasic will wait for "123", then take the next character and return its value as a number. In the example you gave ("A123AB"), this will be the value of "A" as a number (which is $41 or 65 in decimal).
  • martijnmartijn Posts: 6
    edited 2008-01-27 11:53
    thanks for the quick reply. Ok off course, because "A" is not a DEC. i understand,
    My final code is now:

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

    serData VAR Byte

    Main:
    SEROUT 6, 16468, [noparse][[/noparse]"A"]
    SERIN 7, 16780, [noparse][[/noparse]WAIT("123"), serData]

    IF serData = 65 THEN
    GOSUB LichtAan
    ENDIF

    GOTO main
    LichtAan:
    HIGH 8
    PAUSE 1000
    LOW 8
    RETURN


    Although i think the IF line is not good. The code is also not working.. Is the line: IF serData = 65 THEN.... correct??
    Thanks for helping me, i really appreciate it!

    martijn
  • FranklinFranklin Posts: 4,747
    edited 2008-01-27 16:07
    How are you connected to the device that sends the 123A to the stamp? What program is reading the A you send out and returns the string you are looking for?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2008-01-27 16:20
    Hi martijn, it looks like what you have should work now but I was wondering what devices you have connected and at what baud rates.

    I see you have serout on P6 at 9600 and serin on P7 at 2400 both inverted (the earlier program had serin on P1 now P7 maybe a typo or a change)

    Depending on what you have connected you may need serin at 2400 true which would be a baud rate of 396.

    Jeff T.
  • martijnmartijn Posts: 6
    edited 2008-01-27 20:04
    Franklin, iis now working, but for your interest·its connected with a serial cable.. the A was just for debuggin (So i can see if the connection was working).
    Unsoundcode;·Off course! i didnt change the baud rate and focus to much on the function. I'm sorry for the lack of that. It works now great and i can go further with my project, Thanks for your help! Martijn
Sign In or Register to comment.