61
edits
Changes
no edit summary
[[Image:mid3.jpg|center|400px|thumb|]]
</center>
==Final: Arduino==
"Life isn't about the number of breaths we take, but the moments that take our breath away." I find this statement intriguing and then I was inspired to do something involving with air. My idea is to build a birthday cake with candles on top, so that when a person blows on the fire, the cake will sing to that person. However, trying to make both flames in contact is quite hard. I want people to experience that it is much more difficult to see life pessimistically (trying your hardest just to hear the melody) and it is easier when we just enjoy life, thus the joyful melody. The original plan was actually to use a piezo as the breath detector, using the source code similar to Knock, it would detect air vibrations, which will then send signal to arudino. The arduino would be set up so that whenever it detects air vibrations, a melody will be played. But I had trouble figuring it out, so, instead I resorted to manual connection, in which the person must blow the flames in order to close the circuit.
:: Visualization ::
[[Image:DSC_0024.jpg|center|400px|thumb|<center><b>One side</b></center>]]
:: Diagram ::
[[Image:mid1.jpg|center|400px|thumb|<center><b>One side</b></center>]]
:: Documentation ::
[[Image:DSC_0011.jpg|center|400px|thumb|<center><b>One side</b></center>]]
[[Image:DSC_0014.jpg|center|400px|thumb|<center><b>One side</b></center>]]
[[Image:DSC_0015.jpg|center|400px|thumb|<center><b>One side</b></center>]]
[[Image:DSC_0017.jpg|center|400px|thumb|<center><b>One side</b></center>]]
[[Image:DSC_0020.jpg|center|400px|thumb|<center><b>One side</b></center>]]
[[Image:DSC_0024.jpg|center|400px|thumb|<center><b>One side</b></center>]]
:: Source Code ::
<pre>
int speakerPin = 9;
int length = 25; // the number of notes
char notes[] = "ccdcfeccdcgfccCafedAAafgf "; // a space represents a rest
int beats[] = { 2, 1, 2, 2, 2, 4, 2, 1, 2, 2, 2, 4, 2, 1, 2, 2, 2, 2, 4, 2, 1, 2, 2, 2, 4 };
int tempo = 150;
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', 'f', 'g', 'a', 'A', 'b', 'C' };
int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1075, 1014, 956 };
// play the tone corresponding to the note name
for (int i = 0; i < 9; 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 / 1);
}
}
</pre>