Assignment: Input / Output Coincidence Lab Assignment
Collaborators:
Assignment: Input / Output Coincidence Lab Assignment
Collaborators:
Description:
Create an interactive Jack-O-Lantern, just in time for Halloween. The more candy you put in the Jack-O-Lantern shaped bucket, the louder the (sort of but not really) scary first 4 notes to Beethoven's 5th symphony play. Had some issues getting this to work after lots of experiment, so it's a conceptual piece. Also, would have drilled a hole in the bottom of the Jack-O-Lantern pumpkin for a more "seamless" product look -- looks a little weird to have the FSR wires coming out the top. But that'll have to wait until the next iteration
Components Used
- Jack-O-Lantern (plastic, orange, from Wallgreens)
- Kit Kat mini bars (12)
- FSR
- piezo
- cardboard (to cover FSR in bottom of Jack-O
- wires/breadboard, etc.
Arduino Code
/* In theory, this program should play Beethoven's 5th (which is kind of a
* "scary" song when you think about it), everytime a someone adds candy to
* their jack-o-lantern candy bowl. Doesn't really work, but you get the concept
* "Created" by David Rolnitzky, Halloween month, 20009
*/
/* This is the music part, playing beethoven's 5th
* -- a truly creepy song (sort of). Adapted from "Melody" sample on the
* arduino.cc website
*/
int speakerPin = 9;
int length = 15; // the number of notes
char notes[] = "gggx fffd "; // a space represents a rest
int beats[] = { 1, 1, 1, 4,2, 1, 1, 1, 4,2, 1, 1, 1, 4, 1, 1, 1,4 };
int tempo = 300;
void playTone(int tone, int duration) {
for (long i = 0; i < duration * 1000L; i += tone * 2) {
digitalWrite(speakerPin, HIGH);
delayMicroseconds(tone);
digitalWrite(speakerPin, LOW);
delayMicroseconds(tone);
}
}
void playNote(char note, int duration) {
char names[] = { 'c', 'd', 'e', 'x', 'f', 'g', 'a', 'b', 'C' };
int tones[] = { 1915, 1700, 1519, 1450, 1432, 1275, 1136, 1014, 956 };
// play the tone corresponding to the note name
for (int i = 0; i < 8; i++) {
if (names[i] == note) {
playTone(tones[i], duration);
}
}
}
void setup() {
pinMode(speakerPin, OUTPUT);
}
void loop() {
for (int i = 0; i < length; i++) {
if (notes[i] == ' ') {
delay(beats[i] * tempo); // rest
} else {
playNote(notes[i], beats[i] * tempo);
}
// pause between notes
delay(tempo / 2);
}
}
}
/*
* Here is supposed to be some code for the FSR, but after trying for a while
* I had trouble getting it to work....
*/