Is there a way to do an (If Then ) statement in spin I should add If then Goto
mikediv
Posts: 825
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[noparse][[/noparse]pin]:=1····· ' set pin 4 to output
·· !outa[noparse][[/noparse]pin]
·· Dira[noparse][[/noparse]21]:= 0················ ' make pin 21 an input
·· If Then ?????????????????????
·· ina[noparse][[/noparse]21]
·· outa[noparse][[/noparse]6] := ina[noparse][[/noparse]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
·
CON
··· _clkmode = xtal1 + pll16x
··· _xinfreq = 5_000_000
Con Pin=4···· 'set pin to equal 4
Pub myledandinput
·· dira[noparse][[/noparse]pin]:=1····· ' set pin 4 to output
·· !outa[noparse][[/noparse]pin]
·· Dira[noparse][[/noparse]21]:= 0················ ' make pin 21 an input
·· If Then ?????????????????????
·· ina[noparse][[/noparse]21]
·· outa[noparse][[/noparse]6] := ina[noparse][[/noparse]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
·
Comments
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.
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[noparse][[/noparse] 4 ]==1".
Post Edited (MagIO2) : 3/30/2009 7:15:26 PM GMT
you have to do [noparse][[/noparse] 2 ] with spaces in otherwise it changes font size like so· this is [noparse][[/noparse] 2 ]· this is [noparse][[/noparse] 3 ]· etc.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
http://www.propgfx.co.uk/forum/·home of the PropGFX Lite
·
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 has crystal, eeprom, and programing header in a 40 pin dip 0.7" pitch module with uSD reader, and RTC options.
·