Shop OBEX P1 Docs P2 Docs Learn Events
Variable Not Responding — Parallax Forums

Variable Not Responding

kt88seampkt88seamp Posts: 112
edited 2009-11-21 20:49 in Propeller 1
Yeah I finally got a prop [noparse]:)[/noparse]

I have been playing around with spin with a bunch of quick success. Part of getting down to the nitty gritty is with the weird issue I am having. The solution to the problem is probably simple but still no sucess after messing around trying to get it to work.

CON
_xinfreq = 5_000_000
_clkmode = xtal1 + pll16x

PUB Main

dira[noparse][[/noparse]0..3] := %1111 
LEDBlink(0, 1/4)

PUB LEDBlink(pin, freq) 
                                                                  
  repeat
    
    outa[noparse][[/noparse]pin] := 1 
    waitcnt((clkfreq * freq) + cnt) 
    outa[noparse][[/noparse]pin] := 0        
    waitcnt((clkfreq * freq) + cnt)




I am trying to pass a fraction parameter to the LED blink method but it only wants to pass integers for some reason.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-11-21 20:49
    It only passes integers because that's all there is. There are no fractions in Spin nor much in the way of floating point. You can do scaling where you represent fractions as integers like making LEDBlink take "freq" as tenths or hundredths of a second:
    PUB Main
    dira[noparse][[/noparse]0..3] := %1111 
    LEDBlink(0, 25)
    
    PUB LEDBlink(pin, freq)                                                 
      repeat
        outa[noparse][[/noparse]pin] := 1 
        waitcnt((clkfreq / 100 * freq) + cnt) 
        outa[noparse][[/noparse]pin] := 0        
        waitcnt((clkfreq / 100 * freq) + cnt)
    
Sign In or Register to comment.