Description
I put FRSs,a green LED, and a Piezo Speaker inside a half opacity rubber sculpture. If I will push FRSs inside the sculpture, light and sound will be generated in it. In other wards, the sculpture is a pakage to make an Input/Output product.
Components
A rubber Sculpture, a green LED, FSRs, a Piezo Speaker, Arduino Board, Bread Board, wires,
Arduino Codes
int fsrIn = 0; // the inputpin for FSRs
int gOut = 9; // goes to Green LED
int fsrVal = 0; // Variables to store the input from FSRs
int speakerPin = 7;
int soundval = 0;
int i = 0; // Loop counter
int wait = (1000); // Delay between most recent pot adjustment and output
int checkSum = 0; // Aggregate pot values
int prevCheckSum = 0;
int sens = 3; // Sensitivity theshold, to prevent small changes in
// pot values from triggering false reporting
// FLAGS
int PRINT = 1; // Set to 1 to output values
int DEBUG = 1; // Set to 1 to turn on debugging output
void setup()
{
pinMode(gOut, OUTPUT); // sets the digital pins as GreenLED
Serial.begin(9600); // Open serial communication for reporting
pinMode(speakerPin, OUTPUT);
beginSerial(9600);
Serial.println("ready");
}
void loop()
{
i += 1; // Count loop
fsrVal = analogRead(fsrIn) / 4; // read input pin1, convert to 0-255 scale
analogWrite(gOut, fsrVal); // Send new values to GreenLED
if (i % wait == 0) // If enough time has passed...
{
checkSum = fsrVal+fsrVal; // ...add up the 2 values.
if ( abs(checkSum - prevCheckSum) > sens ) // If old and new values differ
// above sensitivity threshold
{
if (PRINT) // ...and if the PRINT flag is set...
{
Serial.print("A: "); // ...then print the values.
Serial.print(fsrVal);
Serial.print("\t");
PRINT = 0;
}
}
else
{
PRINT = 1; // Re-set the flag
}
prevCheckSum = checkSum; // Update the values
if (DEBUG) // If we want debugging output as well...
{
Serial.print(checkSum);
Serial.print("<=>");
Serial.print(prevCheckSum);
Serial.print("\tPrint: ");
Serial.println(PRINT);
}
}
digitalWrite(speakerPin, LOW);
soundval = analogRead(fsrIn); // read value from the sensor
soundval = soundval*2; // process the value a little
//val = val/2; // process the value a little
for( int i=0; i<500; i++ ) { // play it for 50 cycles
digitalWrite(speakerPin, HIGH);
delayMicroseconds(soundval);
digitalWrite(speakerPin, LOW);
delayMicroseconds(soundval);
}
}