One of my favorite musicians is the guitarist from the band Phish -- Trey Anastasio. He plays a mean guitar and sometimes a trippy theremin.For class no. 4 in physical computing we were asked to create an analog output circuit. My mind went immediately to creating a theremin after applying the tone() function to a piezo in class.
Why not create a theremin to jam with your favorite musician, right? Below is my attempt at a v.1 theremin:
Here is the entire song of Trey Anastasio and OysterHead playing Shadow of a Man live.
The code was fairly simple to produce the theremin effect:
const int speakerPin = 9;
void setup() {
pinMode(speakerPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
int senState = analogRead(A0);
int frequency = map(senState, 500, 1000, 3000, 50);
tone(speakerPin, frequency);
Serial.println(senState);
}
The tone() function gives you the ability to change the frequency, when mapped to the light sensor using the map() function, based on how much light it emitted on the light sensor.
Because I wanted to have the theremin be making noise in the dark, the 3000 number was used first in the 'min & max' of the mapping function.
ex.
map(potState, 500, 100, 3000, 50);
rather than
map(potState, 500, 100, 50, 3000);
If I were to use the second map() function in the example, then the piezo would only make sound if the light was removed from the sensor.
The components list:
- light sensor
- 10K resistor
- A3 piezo