Shop OBEX P1 Docs P2 Docs Learn Events
Is there a way to do an (If Then ) statement in spin I should add If then Goto — Parallax Forums

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

mikedivmikediv Posts: 825
edited 2009-03-31 00:17 in Propeller 1
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
·

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-03-30 17:17
    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.
  • MagIO2MagIO2 Posts: 2,243
    edited 2009-03-30 17:17
    If ina[noparse][[/noparse] 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[noparse][[/noparse] 4 ]==1".

    Post Edited (MagIO2) : 3/30/2009 7:15:26 PM GMT
  • BaggersBaggers Posts: 3,019
    edited 2009-03-30 18:07
    MagIO2,

    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

    ·
  • mctriviamctrivia Posts: 3,772
    edited 2009-03-30 18:29
    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 has crystal, eeprom, and programing header in a 40 pin dip 0.7" pitch module with uSD reader, and RTC options.
  • mikedivmikediv Posts: 825
    edited 2009-03-31 00:17
    Thanks guys both examples worked out for me
    ·
Sign In or Register to comment.