Shop OBEX P1 Docs P2 Docs Learn Events
trying to figure out simple code with BS2 — Parallax Forums

trying to figure out simple code with BS2

Hello;
I was wondering if someone can look at the code i put together and help me with a problem. Basically, all I want to do is write in the code that when P15 senses 5 volts when I toggle P7 high it goes to the part of the code that initializes the Epic2. Here is what I have.



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

signal CON 15
OUTPUT signal
x VAR Bit
delay CON 1500
x =0
Main:
x =IN7

PAUSE delay
OUT15 =x
GOTO Main


EMIC_TX PIN 0 ' Serial output (connects to Emic 2 SIN)
EMIC_RX PIN 1 ' Serial input (connects to Emic 2 SOUT)

#SELECT $STAMP
#CASE BS2
T9600 CON 84

#ENDSELECT

EmicBaud CON T9600

Init:


SEROUT EMIC_TX, EmicBaud, [CR]

SEROUT EMIC_TX, EmicBaud, ["N0", CR]
SEROUT EMIC_TX, EmicBaud, ["W150",CR]

PAUSE 250

SEROUT EMIC_TX, EmicBaud, ["S", "Hello.", CR]
SERIN EMIC_RX, EmicBaud, [WAIT(":")]
PAUSE 700
END


If you can assist me with this, that would be great.


Best regards,

Javier

Comments

  • Your program is running in a very tight loop you have named Main: which makes x equal the state of P7, waits 1.5 seconds and then makes P15 equal to x, and repeats forever. If you want to run the init: code when P15 is at 5 volts, or logic 1, insert an IF...THEN statement between OUT15 = x and GOTO Main.
    Main:
     x =IN7
    
     PAUSE delay
     OUT15 =x
     IF x = 1 THEN Init            '<---------
     GOTO Main
    
  • Hal: Thank you for your quik response. Im very new to this programming stuff. Im good with hardware, but very novice when it comes to code. I use the command you mentioned, and it worked perfectly!!!!
    Thank you!!
  • You're welcome!
  • ercoerco Posts: 20,257
    Welcome to the forum Einstein1879! You have been helped by Hal, who has been Mr Jonny-on-the-Spot lately, fielding questions quickly and expertly.

    Kudos Hal, your diligence, enthusiasm and excellence has not gone unnoticed!
  • Thank you for the kind words, Erco!
    I take my cues from the many wonderful people on this forum who all are very giving of their time and expertise. I am truly in awe of the vast amount of free information that is so eagerly given by all the gifted people here. I always look forward to all the wonderful treasures you are able to find and share with us.

    Hal
Sign In or Register to comment.