Introduction: Theremin With Processing
A theremin is a unique instrument that is completely contactless. Instead of musicians handling the instrument, they simply move their hands in the air above. The position of the musician's hands determines the sound produced. Check out this video for an example.
In this project, you will recreate this futuristic, non-contact effect using a Distance Phidget
Supplies
- VINT Hub
- Distance Phidget
Step 1: Setup
Attach the Distance Phidget to your VINT Hub and your VINT Hub to your computer.
Step 2: Write Code - Processing
//Add Phidgets Library
import com.phidget22.*;
//Add Sound library
import processing.sound.*;
//Define
DistanceSensor pitch;
SinOsc sine;
void setup(){
try{
//Create
pitch = new DistanceSensor();
sine = new SinOsc(this);
sine.play();
//Open
pitch.open(1000);
//Configure
pitch.setDataInterval(pitch.getMinDataInterval());
}catch(Exception e){
//Handle Exceptions
e.printStackTrace();
}
}
void draw(){
try{
//Use your Phidgets
println("Freq Distance: " + pitch.getDistance());
//Map distance to frequency
float freqResult = map(pitch.getDistance(), 0, pitch.getMaxDistance(),20.0,1000.0);
sine.freq(freqResult);
delay(30);
}catch(Exception e){
//Handle Exceptions
//e.printStackTrace();
}
}Step 3: Data Interval
If you haven’t already, make sure to check out the Advanced Lesson on Data Interval to understand the code.
Step 4: Mapping
In the code above, the map function is used to map the Distance Phidget output to a reasonable frequency range. You can learn more about the map function here.
Step 5: Learn More
Learn more at phidgets.com/education
Are you a teacher? Sign up for a FREE kit here: phidgets.com/education/free





