I was happy with the data and I thought I could use it to build a simple theremin. To generate the tone and change the frequency I used the WebAudio API. First I started playing a constant tone:
Then I changed the frequency with the .frequency method:
Here’s how the demo looked after:
You might ask why we didn’t use the Proximity API for this task. Firstly, the proximity sensor this API accesses only detects up to around 10 centimetres. Also, it only returns near or far and not the actual distance in centimeters.
Please note that both the devicelight and the proximity APIs are currently only supported on Firefox.