Description:
As a kid, I received a number of Matryoshka dolls, one of which was made of cats. The cats are containers for each other. For instance, A large cat opens in two, and a smaller cat appears. That smaller cat opens and an even smaller cat and so on and so on. I thought it'd be fun to play with this aspect of discover by adding some Arduino fun. I mounted a FSR and Piezo speaker on the bottom of the big cat. I close a photo cell inside the big cat. Pushing the big cat on the table makes it beep a low beep, opening the big cat and revealing the little cat makes a smaller beep for a sort of mom/baby effect.
Materials:
Arduino Code:
//Katzen
//By Laura Devendorf
//Play a high note when photocell and fsr have values
//Play a low note when only the fsr has a value
//Play nothing when nothing has input
int fsrPin = 0;
int photoCellPin = 1;
int speakerPin = 7;
int fsrVal = 0;
int photoCellVal = 0;
int tones[] = {956,1915}; // a high tone and a low tone
void setup() {
pinMode(speakerPin, OUTPUT);
Serial.begin(9600);
Serial.println("ready");
}
void loop() {
digitalWrite(speakerPin, LOW);
fsrVal = analogRead(fsrPin); // read value from the fsr
photoCellVal = analogRead(photoCellPin); //read the value from the photo cell
//print out values to define the range.
Serial.print("FSR ");
Serial.print(fsrVal);
Serial.print(" PhotoCell ");
Serial.println(photoCellVal);
if (fsrVal > 0){
if(photoCellVal > 100) {
//play the high note
for( int i=0; i<50; i++ ) {
digitalWrite(speakerPin,HIGH);
delayMicroseconds(tones[0]);
digitalWrite(speakerPin, LOW);
delayMicroseconds(tones[0]);
}
}
else{
//play the low note
for( int i=0; i<50; i++ ) {
digitalWrite(speakerPin,HIGH);
delayMicroseconds(tones[1]);
digitalWrite(speakerPin, LOW);
delayMicroseconds(tones[1]);
}
}
}
else{
// do nothing
digitalWrite(speakerPin, 0);
}
delay(100);
}