Description:
In this lab I created a instrument that, when the matchbox slid back and forth, the sound of the piezzo speaker would warp. The matchbox basically serveda as a sensor tool, letting the light come into the matchbox and therefore the sensor reads different frequencies.
Materials:
Arduino
Breadboard
Wires
Piezzo speaker
Matchbox
Resistors
Code:
/* Theremin
* --------
*
*
* Created 24 October 2006
* copyleft 2006 Tod E. Kurt <tod@todbot.com
* http://todbot.com/
*/
int potPin = 0; // select the input pin for the potentiometer
int speakerPin = 7;
int val = 0;
void setup() {
pinMode(speakerPin, OUTPUT);
Serial.begin(9600);
Serial.println("ready");
}
void loop() {
digitalWrite(speakerPin, LOW);
val = analogRead(potPin); // read value from the sensor
val = val*2; // process the value a little
//val = val/2; // process the value a little
for( int i=0; i<50; i++ ) { // play it for 50 cycles
digitalWrite(speakerPin, HIGH);
delayMicroseconds(val);
digitalWrite(speakerPin, LOW);
delayMicroseconds(val);
}
}
- Login to post comments