PDA

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



mikediv
03-31-2009, 01:10 AM
Hi guys here is a very simple spin program
CON
иии _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, 01: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.

MagIO2
03-31-2009, 01:17 AM
If ina[ 4 ]
' write whatever commands needed or call a pub procedure here
else
' 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

Baggers
03-31-2009, 02:07 AM
MagIO2,

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

и

mctrivia
03-31-2009, 02: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.

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