Change Variable Based On Range


#1

I want to change a variable based on an input and a possible range. Similar to how rainbowValue sets a color but based on numbers,

For example. If the temperature is between 70 and 80 set the variable to a number between 0 and 100.
RainbowValue(Temp, 70, ’0’, 80, ’100’)

71 would return a value of 10
72 would return a value of 20

I can create a simple piston to figure out this example but I’m wondering if there’s an expression that’ll do it for me.


#2

For your example, it is a simple equation:

output=((input-minInput)/(maxInput-minInput))*(maxOutput-minOutput)

I put together a simple piston to demonstrate:

Which produces:

1/13/2021, 8:44:44 AM +159ms
+52ms	║For input 70, interpolated value is 0
+89ms	║For input 71, interpolated value is 10
+120ms	║For input 72, interpolated value is 20
+152ms	║For input 73, interpolated value is 30
+186ms	║For input 74, interpolated value is 40
+217ms	║For input 75, interpolated value is 50
+249ms	║For input 76, interpolated value is 60
+281ms	║For input 77, interpolated value is 70
+312ms	║For input 78, interpolated value is 80
+344ms	║For input 79, interpolated value is 90
+376ms	║For input 80, interpolated value is 100