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.
“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.
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: