PDA

View Full Version : Propeller Math



MD2010
11-12-2010, 06:20 PM
I am trying to do a simple math calculation and turn LEDís on.
outa[8..15] := 0 Ďwill not turn any on
outa[8..15] := 255 Ďwill turn all on
My formula is var2 := (var1 - 800)/4.70588.
outa[8..15] := var2
I understand that var1 needs to be a long and Var2 needs to be an int, but I donít know how to do that.
The variable input, var1, will be between 800 and 2000, so the results, var2, will be between 0 and 255.

Dave Hein
11-12-2010, 06:23 PM
var2 := (var1 - 800) * 255 / 1200

MD2010
11-12-2010, 06:36 PM
Thanks itís working now. That was simple.