In our previous blog post, we Put the U in FUnicorn; this month, we’re all about the F! With our shield headers in place, and so many available Arduino shields, the world is our oyster, or whatever the unicorn equivalent is – probably some kind of fancy berry or something! In our previous blog post, we alluded to a Wi-FUnicorn, but that beast will have to remain mythical for now, since we ran into some pin conflicts and other issues that made its performance a little less stable than we’d have typically preferred. So, we headed back to the drawing board with a blank canvas – or more accurately, a blank proto shield – specifically, Arduino’s Proto Shield Rev3 for the Arduino Uno, which in addition to the typical prototyping area found on most boards of its ilk, has those really nice labeled pins like the newer Arduino boards, and also a great little SMD area where you can add a 24-pin (or fewer) SOIC.
The FUnicorn is literally one flashy pony out of the box, but we wanted to really make it shine. The protoboard made it easy to add more LEDs, but that wasn’t enough – we wanted to really put on a serious dog and pony show. So, we thought: what if we made our filly a bit more philharmonic? Browsing audio shields, we noticed a common theme: they typically used SPI, and since the FUnicorn LEDs already use those same pins for PWM pulsing, they were unavailable. However, I2C, UART, analog, and many digital I/O pins are free and clear! So we looked at other modules, eventually settling on the $15 “WayinTop Sound Module Button Control Music Voice Player Programmable Talk Chip” on Amazon, which rather than relying on a complicated SPI bus, would allow us to trigger a preloaded MP3 with high or low, similar to a button.
Due to the its capacitive touch interface, which works by using a pullup to stick a voltage on a pin and measure how fast it decays, the FUnicorn must constantly poll to see if its giant golden likeness is being interacted with. This presented a challenge for our additional functionality that we wanted to layer on top, since we wanted our LED and audio to have some specific timing characteristics in order to put on the show as we’d envisioned it. In the end, we solved this by playing a short LED animation as part of the capacitive touch loop, counting down the number of cycles we needed to approximately match the length of our audio, after the initial built-in animation (which is blocking) has completed. An extract of this code can be found below, and the full example can be found in our GitHub repo, or the Examples > Alpenglow FUnicorn menu if you already have the library installed, and have updated it.
With everything now working precisely how we envisioned it – or close enough – allow us to demonstrate to you the glorious result:
We couldn’t think of any lyrics that better represent our marvelous mare than Mermaid Sisters’ Galactic Mermaid from Shinichirō Watanabe's Carole & Tuesday (which is where the "B" in FBUnicorn comes from!), though of course you can load as filthy or clean of a song as you like onto the board’s microSD card. If you build this project, let us know what song you chose, or maybe in the next installment we’ll get that Wi-Fi working and turn the FUnicorn into a networked jukebox so that you can pick your favorite track remotely!