My goal for this week’s application of the labs was to create a music box with a touch sensor that plays “Papa Loves Mambo” when the touch sensor pressed. The intro of the song would play once (in set up) and the first verse would loop over and over again.
WHY?
“Papa Loves Mambo” is my dog’s breakfast song. When he hears it, he knows that it is meal time. I want to create a device where he can interact with us and communicate to us when he is hungry. If he presses this and hears the song, he will associate it with food. So the goal would be to get him to press it when he wants something to eat.
The Struggles/Process
Converting the song from sheet music to code, then from code notes into beats took a chunk of time. But once I figured out where the code related to notes on the piano, the process went smoother.
I then wrote the code and tested the beats to sound. At one point it was very off and sounded very bizarre. It turns out I had some mis-matched code, as well as some octaves off, so I went through and fixed that until I got the song to play intro once and verse on loop.
I then tried to add a touch sensor to active the sound. However, I could not get any reading on the touch sensor that I had after many attempts. Therefore, mapping it and using it as a sensor at all proved to be difficult. I tried other sensors and then I decided to work with just a regular button. But I could not, for the life of me, get the button to activate the song with the code that I had. The song would just keep playing as soon as it was uploaded/plugged in.
I did do some office hours with Sam Levine and he helped me get a single button to activate the entire song. We added a variable (button), moved the entirety of the song – intro and verse- into a new function that we created, added another variable…etc. At this point I am not 100% sure that I could recreate this on my own. But it is good to see the code in action so I can play with it and learn from it.
However, I still want to be able to have the verse loop and add the touch sensor. It took a lot of time to reach a point of being stuck. I also wanted to try to get the song to stop playing with the touch of the button, but I would need to really understand millis () to apply this.
___________________________________________
Here are the videos from the labs:
Tom Igoe
THis is good progress, and good documentation.
One thing that strikes me listening to it is that the song (and the mambo) relies on syncopation, which requires varied spacing between the notes. That’s a tricky thing to pull off even for an experienced coder, but it gives you a goal to consider long term.
When you’re making a melody, there’s a tradeoff between interactivity and fidelity to the song. The easiest way to get the melody and rhythm is to use delays, but they stop things from being interactive. It’s a good way to figure out the melody though. Then you can work out how to make it interactive later.
If you press the button during the song, what happens?
angela
Yes! It is in a very basic quarter note, whole note, half note rhythm with pauses or longer notes to account for the various patterns. Which makes it not perfectly matching to the sheet music. I really want to figure out how to apply delay/millis to make this pattern work exactly, if that is even possible.
In the end, if I had to choose a tradeoff, the interactivity is more important, as the essence of the song can essentially be inferred (maybe not by my dog) but by people who listen to this genre.
If you press the button during the song, nothing happens. I wanted to work out a way to get it to stop. I talked with Sam on how to get this to happen and it was leading back to millis. At that point I just wanted to be able to figure out on my own how to get the button to work.