Wednesday 8 August 2007

swapping values from light sensors

The sensor values move clips and control their timelines, however i wish to reverse the incoming values on one sensor to control volume. So i want volume to be = to 0 when sensor value = 1023. and volume to proportionally increase to 100 when sensor value drops to 0.


newvalue = ( (1023 - incomingvalue) * 100 ) / 1023

I have adapted the code slightly, it gives a good reverse set of values scaled down between 0 and 100, I have added the math.round to get rid of the long numbers!. Tried to cut it down to one calculation using Math.round but for some reason it would not work. But it works, so thanks.

ratio2 = Math.round((1023 - ain1)* 100) / 1023;
ratio1 = Math.round (ratio2);

No comments: