Description
Create a single artifact that incorporates both input and output. I made a musical squeeze box using a cardboard box. When you squeeze the sides of the box it outputs a musical tone. You can twist the knob at the end to change the pitch of the output noise (musical note).
Components Used
1 Resistors
1 Potentiometers
1 Force Sensitive Resistor
1 Piezo Speaker
cardboard box and sponge foam
Arduino Code
/*
* Joshua Gomez - Lab 5
*
* This code is for a music box
* By pressing the button a sound is emitted
* The sound played is detremined by the value of the POT input
*/
int potPin = 0; // select the input pin for the potentiometer
int fsrPin = 5; // select the input pin for the FSR
int speakerPin = 11;// set the output pin for the piezo speaker
int potVal = 0;
int fsrVal = 0;
void setup() {
pinMode(speakerPin, OUTPUT);
beginSerial(9600);
Serial.println("ready");
}
void loop() {
fsrVal = analogRead(fsrPin);
if(fsrVal>10)
{
potVal = analogRead(potPin) + 950;
for( int i=0; i<200; i++)
{
digitalWrite(speakerPin, HIGH);
delayMicroseconds(potVal);
digitalWrite(speakerPin, LOW);
delayMicroseconds(potVal);
}
}
else
digitalWrite(speakerPin, LOW);
}
Item
Squeeze Box
Squeeze Box
Squeeze Box