Hello all,
I am trying to build a midi controller that incorporates an accellerometer. I have one of the 2 axis accelerometers from Dimension Engineering. The behavior that I would like is for the midi output to follow the tilt of the accelerometer on each axis from -90 degrees to +90 degrees. In other words, if the accelerometer were in its neutral position, the midi controllers associated with each axis would spit out a value of 64. If tilted to a full 90 degrees in a given direction the midi output for that axis would spit out either 0 or 127. Make sense?
Ok, the problem is that when tilted 90 degrees from neutral, the accelerometer does not reach its limit (0v or 5v). The values I get from the ADC at 90 degrees from neutral are about 45 to 85. Here is a snippet of the code where I get and process the adc value.
ADCIN 1,modval ' Read channel 1 to modval
modval = modval/2
The divide by 2 is just the simplest way I could think of to get the result from 8 bit to 7 bit (for MIDI) that I could think of. I am sure there is an easier way.
So, my question is, what is the best way to go about scaling an adc result of between 45 and 85 to the desired results of 0 to 127.
thanks in advance for the help!
Brad