View Full Version : Is there a way to do an (If Then ) statement in spin I should add If then Goto

03-31-2009, 12:10 AM
Hi guys here is a very simple spin program
иии _clkmode = xtal1 + pll16x
иии _xinfreq = 5_000_000
Con Pin=4ииии 'set pin to equal 4
Pub myledandinput
ии dira[pin]:=1иииии ' set pin 4 to output
ии !outa[pin]
ии Dira[21]:= 0ииииииииииииииии ' make pin 21 an input
ии If Then ?????????????????????
ии ina[21]
ии outa[6] := ina[21]иииииииииииииииииии ' Copy P21 input to P6 ouput

I need to use a command like If-Then I can not find anything in the manual ,,that I understand anyway" on how to do this.
I want to read an input pin and "IF" its in a certain conditon jump to another part of the program so something like If pin 4 equals 1 then goto Con or Pub??
As always thanks in advance

Mike Green
03-31-2009, 12:17 AM
There is an IF statement. It doesn't use THEN. Spin uses indenting for that sort of thing.

There are no gotos in Spin, so you can't goto some other part of your program. You have to use the various structured statements like IF and REPEAT and CASE. There are plenty of examples in the Propeller Manual and the tutorials. There's a getting started 'sticky' thread: http://forums.parallax.com/showthread.php?p=791527.

03-31-2009, 12:17 AM
If ina[ 4 ]
' write whatever commands needed or call a pub procedure here
' do something else

Please note: The indentation is very important here.

The condition in if is true, whenever the value is different from 0 (zero). The condition given here is equal to "if ina[ 4 ]==1".

Post Edited (MagIO2) : 3/30/2009 7:15:26 PM GMT

03-31-2009, 01:07 AM

you have to do [ 2 ] with spaces in otherwise it changes font size like soи this is [ 2 ]и this is [ 3 ]и etc.

http://www.propgfx.co.uk/forum/иhome of the PropGFX Lite


03-31-2009, 01:29 AM
if ina

is the same as if ina!=0

not ==1 if it=2 it is still true

Need to make your prop design easier or secure? Get a PropMod (http://propmodule.com) has crystal, eeprom, and programing header in a 40 pin dip 0.7" pitch module with uSD reader, and RTC options.

03-31-2009, 07:17 AM
Thanks guys both examples worked out for me