Shop OBEX P1 Docs P2 Docs Learn Events
serin a value and goto a label — Parallax Forums

serin a value and goto a label

anthonycarsonanthonycarson Posts: 1
edited 2008-09-12 18:51 in BASIC Stamp
' {$STAMP BS2}
value·· VAR Byte
start:
SERIN 16,16468, [noparse][[/noparse]HEX value]
IF value = 61 THEN relay1
IF value = 62 THEN relay2
GOTO start:
relay1:
DEBUG "testing relay 1"· ,CR
HIGH 7
GOTO relayOff
relay2:
DEBUG "testing relay 2"·· ,CR
HIGH 8
GOTO relayOff
relayOff:
SERIN 16,16468,[noparse][[/noparse]value]
IF value = 61 THEN relayOff2
GOTO relayOff

relayOff2
DEBUG "turning relay off!" ,CR
LOW 7
LOW 8
GOTO start:

This code is supposed to allow a input from the keyboard in ascII 9600 8 N 1 to the stamp to turn on a relay at pin 7 and pin 8. When the letter "a" or "b" in lower case is typed into the keyboard the program instructs it to go to the corresponding label and run the label while waiting another input of the letter "a" in lower case. It is not working! Why? is the HEX supposed to have another modifier? or the varriable "value" not a kosher word to use? Something makes the code not function like desired... Please help!

Anthony

Comments

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2008-09-12 18:51
    anthony -

    Try the following modification which is a bit easier to understand.

    As it is:

    start:
    SERIN 16,16468, [noparse][[/noparse]HEX value]
    IF value = 61 THEN relay1
    IF value = 62 THEN relay2

    With changes made:

    start:
    SERIN 16,16468, [noparse][[/noparse]value]
    IF value = "a" THEN relay1
    IF value = "b" THEN relay2

    Now it's a good deal more self-documenting.

    Just as a matter of reference, you may also want to look at the DEBUGIN PBasic command.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Involvement and committment can be best understood by looking at a plate of ham and eggs. The chicken was involved, but the pig was committed. ANON
Sign In or Register to comment.