Shop OBEX P1 Docs P2 Docs Learn Events
BS2sx — Parallax Forums

BS2sx

leshea2leshea2 Posts: 83
edited 2005-08-18 04:39 in BASIC Stamp
How would I add another line of code to this command, if I want to make the BS2sx stamp flash an LED on and off once, to confirm the this part of the code,

Send_Msg:
DO
READ eePntr, char
eePntr = eePntr + 1
IF (char = 0) THEN EXIT
SEROUT Sout, Baud, [noparse][[/noparse]char]
LOOP
RETURN


was successful executed ?

Thanks !


' {$STAMP BS2sx}
' {$PBASIC 2.5}

Sout PIN 0

Baud CON 17405

eePntr VAR Word
char VAR Byte

Msg1 DATA "Call 18004459889 at 4:35 p.m.", 0


Main:
eePntr = Msg1
GOSUB Send_Msg
END


Send_Msg:
DO
READ eePntr, char
eePntr = eePntr + 1
IF (char = 0) THEN EXIT
SEROUT Sout, Baud, [noparse][[/noparse]char]
LOOP
RETURN

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-08-17 22:02
    Is this a trick question?...

    Success:
    · HIGH Led
    · PAUSE 100
    · LOW Led

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • leshea2leshea2 Posts: 83
    edited 2005-08-17 22:23
    So will this code work, I mean will both of the commands in this code work ?



    ' {$STAMP BS2sx}
    ' {$PBASIC 2.5}

    Sout PIN 0

    Baud CON 17405

    eePntr VAR Word
    char VAR Byte

    Msg1 DATA "Call 18004459889 at 4:35 p.m.", 0


    Main:
    eePntr = Msg1
    GOSUB Send_Msg
    END


    Send_Msg:
    DO
    READ eePntr, char
    eePntr = eePntr + 1
    IF (char = 0) THEN EXIT
    SEROUT Sout, Baud, [noparse][[/noparse]char]
    LOOP
    RETURN

    HIGH Led
    PAUSE 100
    LOW Led

    END
  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-08-17 22:31
    No,


    HIGH Led
    PAUSE 100
    LOW Led

    is never executed since the above function has been RETURNed from and the code never jumps to the LED flashing code. Additionally you have not specified which pin Led is defined as. Either create a new subroutine and GOSUB to it after you've "GOSUB Send_Msg" or just place the code itself after GOSUB Send_Msg, or place the code before the RETURN. Somewhere the execution of your program·must flow through the commands in order for them to be performed, what you have done is created a "dead code" section, meaning you have valid code that is never called or executed.

    You seem to be fundamentally confused on some basic aspects of programming, Please read "What's a Microcontroller" in the Downloads>Stamps In Class section. It is a primer on using the basic stamp and covers alot of the fundamental topics you are confused about.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·1+1=10

    Post Edited (Paul Baker) : 8/17/2005 10:34:58 PM GMT
  • leshea2leshea2 Posts: 83
    edited 2005-08-17 22:46
    Will this work or should I put the Flash LED code before the loop command reference ?

    ' {$STAMP BS2sx}
    ' {$PBASIC 2.5}

    Sout PIN 0

    Baud CON 17405

    eePntr VAR Word
    char VAR Byte

    Msg1 DATA "Call 18004459889 at 4:35 p.m.", 0


    Main:
    eePntr = Msg1
    GOSUB Send_Msg
    END


    Send_Msg:
    DO
    READ eePntr, char
    eePntr = eePntr + 1
    IF (char = 0) THEN EXIT
    SEROUT Sout, Baud, [noparse][[/noparse]char]
    LOOP

    HIGH 0
    PAUSE 1000
    LOW 0
    PAUSE 1000

    END
  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-08-17 22:48
    dagnabit stupid anti-spam filter, Id swear thats longer than 20 seconds.

    Jon and I have been bumping heads answering the question, we kept editing our two posts simulataneously adding the same info, anyways to recap (since the post has been edited and Jon has since removed his).

    This code should work:

    ' {$STAMP BS2sx}
    ' {$PBASIC 2.5}

    Sout PIN 0

    Led· PIN 2

    Baud CON 17405

    eePntr VAR Word
    char VAR Byte

    Msg1 DATA "Call 18004459889 at 4:35 p.m.", 0


    Main:
    eePntr = Msg1
    GOSUB Send_Msg
    END


    Send_Msg:
    DO
    READ eePntr, char
    eePntr = eePntr + 1
    IF (char = 0) THEN EXIT
    SEROUT Sout, Baud, [noparse][[/noparse]char]
    LOOP
    HIGH Led
    PAUSE 100
    LOW Led
    RETURN

    END

    place your LED on pin 2 or redefine the pin in the code.

    Also Jon suggested using·"DEBUG char"·function in place of··"SEROUT Sout, Baud, [noparse][[/noparse]char]", this will output the data to your debug terminal instead of the serial line thereby verifying the data would be sent correctly on the serial line.


    <EDIT> Your adjusted code doesn't have a return anymore, the code will work, but it is not good programming practice to not RETURN from a GOSUB </EDIT>

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·1+1=10
  • leshea2leshea2 Posts: 83
    edited 2005-08-17 22:53
    Thanks for all you help !

    P.S.
    Can I use GOTO main: instead of RETURN
  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-08-17 22:57
    Oh and please please please read "What's a Microcontroller", quite a few of us start to get a bit testy being asked questions that are answered in free downloadable documents.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·1+1=10
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-08-18 04:39
    Yes, please do read WAM.

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