Homage to Keyboard Cat
Description:
Charlie Schmidt's keyboard cat inspired this assignment.
When the cat is squeezed, touched, or poked, Keyboard Cat's songs plays and his eye light up. I used all three LEDS to light up his eyes. Unfortunately, you can't tell in the video! : ( His eyes are made of vellum, which diffused the light in a nice way.
Also, I used the given equation to figure out additional notes.
I sewed a felt cat and placed the FSR and Piezo speaker inside. The cat is also stuffed with polyester stuffing, which is keeping the FSR and speaker secure.
Components
Breadboard
Arduino Microcontroller
RGB LEDs
Resistors
1 FSR
1 Piezo Speaker
For cat:
Felt
Vellum
Polyester Stuff
Sewing supplies
Code
/* Play him off, Keyboard Cat!
* -----------
*
* Charlie Schmidt's keyboard cat inspired this assignment.
* When the cat is squeeze, Keyboard Cat's songs plays and his eye light up.
*
* The calculation of the tones is made following the mathematical
* operation:
*
* (1/(2 * toneFrequency))* 1 million to get PW time
*
* I added a few notes to the table:
*
* Middle C = C4
*
* note frequency period PW (timeHigh)
* g3 (G) 196 hz 2551
* a3 (A) 220 hz 2273
* b3 (B) 245 hz 2041
* c4 261 Hz 3830 1915
* d4 294 Hz 3400 1700
* e4 329 Hz 3038 1519
* f4 349 Hz 2864 1432
* g4 392 Hz 2550 1275
* a4 440 Hz 2272 1136
* b4 493 Hz 2028 1014
* c5 523 Hz 1912 956
*
* (cleft) 2005 D. Cuartielles for K3
*/
int redPin = 9; // selecting LED pin
int bluePin = 11;
int greenPin = 10;
int sensorPin = 0; // select pin for sensor
int sensorVal = 0;
int speakerOut = 7;
byte names[] = {'G','A','B','c', 'd', 'e', 'f', 'g', 'a', 'b', 'cFive'};
int tones[] = {2551,2273, 2041, 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956};
byte melody[] = "3c3e3g3e3c3e3g3e3A3c3e3c3A3c3e3c2G2B2d2B2G2B2d3B2G2G2G2G2G2G2G2G2G3c3e3g3e3c3e3g3e3B3d3f3d3B3d3f3d3A3c3e3C3A3c3e3c5G"; //edited melody to play keyboard cat's song.
// count length: 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
// 10 20 30
int count = 0;
int count2 = 0;
int count3 = 0;
int MAX_COUNT = 116; // the longer the song, the longer this should be. if short, song will cut off.
int statePin = LOW;
void setup() {
pinMode(redPin, OUTPUT); // three pins will light up!
pinMode(bluePin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(speakerOut, OUTPUT);
Serial.begin(9600);s
}
void loop() {
sensorVal = analogRead(sensorPin); // read the value of the sensor
if (sensorVal > 0){ // if sensor val is being touch, turn on Led
for (count = 0; count < MAX_COUNT; count++) {
statePin = !statePin; // causes light to flickr
digitalWrite(redPin, statePin);
digitalWrite(bluePin, statePin);
digitalWrite(greenPin, statePin);
for (count3 = 0; count3 <= (melody[count*2] - 48) * 30; count3++) {
for (count2=0;count2<8;count2++) {
if (names[count2] == melody[count*2 + 1]) {
digitalWrite(speakerOut,HIGH);
delayMicroseconds(tones[count2]);
digitalWrite(speakerOut, LOW);
delayMicroseconds(tones[count2]);
}
if (melody[count*2 + 1] == 'p') {
// make a pause of a certain size
digitalWrite(speakerOut, 0);
delayMicroseconds(500);
}
}
}
}
}
else if (sensorVal == 0){ // need this to turn off loop
digitalWrite(redPin, 0);
digitalWrite(bluePin, 0);
digitalWrite(greenPin, 0);
digitalWrite(speakerOut, 0);
return;
}
}
Movie