I'm trying to make a velocity-sensitive keyboard for playing music.
I have to measure the position of each key in order to know how loud the sound should be.
The volume of the sound is a function of the velocity of the keys at the end of the descent. I know the position can be recovered from the velocity by integrating it.
What would be the cheapest and easiest, yet still reasonably precise way to do it?
I don't know exactly what “reasonably precise” would mean in the context. I'll have to test it.
The length of the maximum displacement is about 2 cm.
EDIT: not as some answers seem to suggest, the loudness is NOT function of the mean velocity of the key.
EDIT2: The loudness is function of the hammer speed at the moment it hits the string, but the key isn't pushing the hammer until the end of its path. It is really like throwing a ball on a wall: the ball leaves the hand at one moment, before it hits the wall.