Hi Roger,
“V” (in this code) is the brightness value that you need to do the math with.
1A. Minimum value: V = Math.max(20,V); (Using Max for minimum value may seem counter-intuitive at first, but you want the higher value of these two)
1B. Maximum value: V = Math.min(100,V); (If you want to set the maximum value to 100)
2. Threshold. This conflicts with the Minimum value code in 1A but basically:if (V<20) {V = 0};
To fix the conflict, you can combine minimum and threshold into one expression: if (V<20) {V = 0} else {V = Math.max(20,V)};
3. Ratio. Linear is a nice way to do this, for example: V = linear(V,20,100,20,50);
This will remap your input values (20-100) to a new range, in this case 20-50. The new range can be any two numbers.
So, it should work by adding this to the end of the existing code (I didn’t test it):
if (V<20) {V = 0} else {V = Math.max(20,V)};
V = Math.min(100,V);
V = linear(V,20,100,20,50);
(You can drop the “V=” on the last line, as the result is used for the brightness value directly.)
Actually, that linear expression already takes care of your minimum and maximum input values. In other words, the whole thing boils down to adding this to the existing code (replacing the last line “V”):
if (V < 20) 0 else linear(V,20,100,20,50);