IF THEN Help
Bassist
Posts: 10
I need to send "sre*" to a 232 device. I am able to do that but I need to send the string when pin0 = 1. I have not been able to figure out the IF THEN· statement. Any help will be appreciated. Thanks in advance.
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
Record:
· IF (IN0 = 1) THEN Main
·Main:
·· DO
· SEROUT 16, 16780, [noparse][[/noparse]"sre*",CR]
· PAUSE 2500
· LOOP
· END
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
IF IN0=1 THEN Main
unless you are using a BS1, in which case
IF PIN0=1 THEN Main
The PBasic editor turns colors to help ID syntax/typing errors. Make sure you used "zero" and not "oh".
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·"If you build it, they will come."
Attach your entire program.
And per Stephen, you must have something like:
Record:
IF (IN0 = 1) THEN Main
goto record' loop back if IN0=0
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·"If you build it, they will come."
' TEST.bs2
' This program transmits the string "sre*" followed by a
' carriage-return at 2400 baud, inverted, N81 format.
' {$STAMP BS2}
' {$PBASIC 2.5}
·INPUT 0
·Record:
· IF IN0 = 1 THEN Main
· GOTO Record
·Main:
· DO
· SEROUT 16, 16780, [noparse][[/noparse]"sre*",CR]
· PAUSE 2500
· LOOP
· END
Main:
DO
SEROUT 16, 16780, [noparse][[/noparse]"sre*",CR,LF]
PAUSE 2500
LOOP
END
It spits out the string repeatedly no matter the state of input 0. I think I need to send the hex representation of sre*CRLF as the string. How do I do this? Thanks, Tab
start loop
serout
wait a while
repeat loop
there is no checking of anything in the loop
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
An If-Then statement works like this:
If IN0 = 1 then do something........if not, then go to the next instruction.
So, if you have:
IF IN0 = 1 then goto main
Main:
send some serial data
END
It will execute the Main routine regardless of pin 0's state because if IN0 = 1, it goes to the routine Main. If IN0 = 0 it falls through the condition (because it's not true) and executes the next command, which happens to be THE MAIN ROUTINE!!!
By doing the
Record:
IF IN0=1 goto Main
goto Record
You'll check pin 0 over and over forever..... or until pin 0 = 1...... the little "GOTO Record" is the next instruction past the If-Then condition, so when the If-Then is false, it executes the next command which starts the check again. When pin 0 = 1, it leaves the little check routine and executes new code (your Main routine)
The END statement stops everything. Period. It don't do no mo' until you power off or hit the reset button..... So depending on what you want you code to do, you might want to put a "Goto Record" after your Main routine, but before the END command.... so if pin 0 = 1, it sends your serial data, then starts the whole program again.
I hope all that makes sense and is helpful..... Now I go back to work [noparse]:)[/noparse]
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"puff"...... Smile, there went another one.