When I was thinking about what to make for this week’s assignment I was came across a clip from The Big Bang Theory where Sheldon was playing the Theremin.
I theremin is the musical instrument that makes sound based on how electromagnetic fields produced by two antennae are altered by the hand movements between the two.
To mimic this I initially tried to use a Ultrasonic sensor to alter the sound. While this worked it only altered the sound based on the distance of the object[hand] from the sensor, the sound was altered based on only one direction.
I then used a LDR to do the same thing. This allowed me to change the sound by moving a light source around the LDR. This allowed me control the sounds by movement of the light source both horizontally and vertically.
I also added a button that multiplies the value of the photoresistor by 2 when pushed once and then the function gets disabled when pushed again. This yields a siren like effect when the button is repeatedly pushed.
int ldrPin = A0; int playButton = 7; bool multiplyFrequency = false; int prevButtonState = LOW; void setup() { Serial.begin(9600); pinMode(ldrPin, INPUT); pinMode(playButton, INPUT); } void loop() { changeState(); Serial.println(multiplyFrequency); // int ultSonData = getUltraSonicData(); int ldrData = getLDRData(); // int transformed = transformData(related); if (multiplyFrequency) { tone(4, ldrData * 1.5); } else { tone(4, ldrData); } } float getLDRData() { return floor(analogRead(ldrPin)); } float changeState() { // Serial.println(digitalRead(playButton)); if (prevButtonState == LOW && digitalRead(playButton) == HIGH) { multiplyFrequency = !multiplyFrequency; } prevButtonState = digitalRead(playButton); }