Tuesday 26 April 2011

How the new shadow harp works



Each of the four analogue inputs as a simple voltage divider.
5V is connected to one side of a light-dependent resistor (LDR), which is wired in series with a resistor to ground. The input signal is taken from between the two resistors.

As the user places their hand over the LDR, the resistance falls, causing the ratio between the two resistors to drop. This variable voltage is fed into an analogue pin, converted to a digital value (0-255) by the microcontroller's ADC hardware and compared to the last value read in.

Even when static, analogue input values tend to "drift" - i.e. float around, +/-1 or +/-2 (so a "constant" value of 128 may actually vary between 126 and 130 over time!)
To overcome this, we take a reading from the analogue pin, compare it to the previous value and if the difference is greater than 2, this represents a genuine change in resistance, which we then process.

In fact, depending on light levels, sometimes it is necessary to adjust this value to 4 or 5, to avoid cross-talk as the user places their hand in a position that influences to LDRs, next to each other. By making this threshold value a variable, we can allow the user to set their own "sensitivity" level for playing the instrument.

In indoor lighting, the LDR inputs typically read around 220.
When you place your hand over an input tube, this value drops to around 205.
Sometimes neighbouring LDR values drop when you place your hand over an input - by setting the sensitivity to 8, in this case, only the sensor with a hand above it actually triggers an input signal.

Triggering inputs is quite simple - if an input value is falling compared to its previous value, this represents the presence of a hand above the input.
When the input value is constant, the hand is still present. When the value is rising, this is the user removing their hand away from the input.

Using Oshonsoft's hidterm DLL and an 8-byte USB buffer, we can send the raw input values AND the trigger values (0 or 1) for four inputs at a time:

No comments:

Post a Comment