As in the example for scaleLinear:
{{scaleLinear 0 100 0 10000 10}} returns 1000 because 10 is 10% of 100, therefore 10% of 10000 is 1000.
So therefore should {{scaleLinear 4000 20000 0 300 8000}} not output 150 ? as 8000 is 50% of 16000( 4000 to 20000 = 16000) , but instead I get 75.
Im using a 4-20mA pressure sensor, so a span of 16mA( min to max ) should scale to a tank depth( 0 to 300 cm ) should it not ?
{{scaleLinear}}
takes the final argument (the value to scale) and maps it from its original domain (the first two arguments) to its new domain (the third and fourth arguments).
So, given …
{{scaleLinear 4000 20000 0 300 8000}}
8000
is 25% of the way up the scale from 4000
to 20000
- as in …
- A value of
4000
would be 0%
(bottom of scale)
- A value of
20000
would be 100%
(top of scale)
- A value of
12000
would be 50%
(halfway between 4000
and 20000
)
So, when you go 25% of the range from 0
to 300
, that gives you 75
.
As a mathematical equation, you can think of {{scaleLinear}}
as doing the following …
scaledValue = (originalValue - fromLow) * (toHigh - toLow) / (fromHigh - fromLow) + toLow
So Im better off usinig 8000/(20000-4000)=50%
Well, does a reading of 4000
mean your tank is empty (at 0
cm) and a reading of 20000
mean your tank is full (300
cm)? And do those readings scale linearly with the tank depth?
Yes its a 4-20mA pressure senor so 4000 is empty and 20000 is full. The depth of the tank varies so I’ve been using:
{{scaleLinear 4000-20000 0 TANK DIAMETER SENSOR_mA OUTPUT}} expecting a depth