Shop OBEX P1 Docs P2 Docs Learn Events
New to spin — Parallax Forums

New to spin

halfblinddadohalfblinddado Posts: 59
edited 2012-12-22 14:57 in Propeller 1
Hello,

I am in the process of moving from the Basic Stamp to the Propeller and I am new to spin. So far I have figured out quite a bit but I am confused as to how to code math problems.

Here is a simple program I am trying to run. It never makes it to the first Debug statement. I know this is newb stuff but any help would be appreciated.
CON

_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000


OBJ

Debug : "FullDuplexSerialPlus"
f32 : "Float32Full"
fString : "FloatString"


PUB TestMessages : z | x1,y1,x2,y2,lfx,lfy
x1 := 10
y1 := 10
x2 := 20
y2 := 20
lfx := f32.Fsub(x2, x1)
lfy := f32.Fsub(y2, y1)
z := f32.Atan2(lfx, lfy)

Debug.start(31, 30, 0, 57600)

repeat
  Debug.str(string("This is a test message!", 13))
  Debug.str(String(13))
  Debug.str(fstring.FloatToString(z))
waitcnt(clkfreq + cnt)

Comments

  • Mark_TMark_T Posts: 1,981
    edited 2012-12-22 12:45
    Code tags make code readable and scrollable! Please use them (# button).

    You lack a call to the start method for Float32Full:
      f32.start
    
  • halfblinddadohalfblinddado Posts: 59
    edited 2012-12-22 12:48
    Thank you. I'm sorry but I don't know what you mean by "code tags" could you please explain?
  • davejamesdavejames Posts: 4,047
    edited 2012-12-22 14:47
    halfblind,

    Surrounding your code samples with "[ code ] [ /code ]" will create a window in which the code is dsplayed and format retained...making things easier to read.

    You can also use the "#" button in the advanced edtor to do the same.

    I took the liberty of editing your original post. Go take a look and you'll see the "code, no code" usage.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-12-22 14:57
    Instead of:
    x1 := 10
    y1 := 10
    x2 := 20
    y2 := 20
    

    You'll want to use:
    x1 := 10.0
    y1 := 10.0
    x2 := 20.0
    y2 := 20.0
    

    so the compiler knows you want the variables/constants encoded as floating point values.

    An alternative is to use the "FFloat" method to convert the integers to floating point numbers.

    Floating point values are encoded differently than normal integers. You can't mix integers and floating point numbers or operations.

    I don't know if you're aware of F32 floating point object. It has all the methods of float32full but uses one cog instead of two.

    F32 does have a problem with its ATan2 method, but I've posted a patched version here that appears to fix the problem for now (I'm hoping someone can make a faster version of my patch).
Sign In or Register to comment.