Close

Pulling it all together

A project log for Stylish!

A most stylish wearable music synthesizer! A real stylus based monophonic music synthesizer built into a giant trucker belt buckle!

t-b-trzepaczT. B. Trzepacz 10/02/2018 at 07:390 Comments

Finally, having a working keyboard, working sound libraries, and a working LED ring, all that is left is to do some software and pull the whole thing together for a first playable.

I had a sample program that had been running on the breadboard version of the project, based on a Mozzi library demo and the WS2812B test program, sort of mashed together into a big mess of code that made sound and did blinky lights, but somehow it wasn't working on this board, now that everything else was debugged. What to do?

After goofing around for awhile with trying to debug it, I decided that the code really needed a restructuring anyway, and decided to rewrite it starting with the last keyboard test program.

The first thing I ended up doing was rewriting that demo program to be more of a library, for clearer, more concise code. I added function callbacks for key-down and key-up events, and combined the arrays for keys and buttons into one to simplify the loop.

The first thing I noticed was that, when I ran the thing flat-out, there were a lot of key events whenever the stylus was moved. Some debouncing was in order.  I ended up implementing a thing called "stable counter" where the state had to not change for awhile before it would trigger the event. I'm not sure this is an optimal solution, but it works for the moment, so I've run with it. 

The next step was to integrate the WS2812B library and get it to animate some LEDs. At first, the keyboard had a bunch of problems again, and I was really annoyed. But I theorized that the WS2812B library setup was stomping on some of the configuration I had to do to get the debugging turned off on keyboard pins. So I switched the order of initialization, and the keyboard started working again!

Here is the first test of the LEDs and keyboards working together:

The next thing to do was integrate the audio library. I had determined that the Mozzi Arduino library worked well with STM32, and had run some previous demo programs on the solderless breadboard version of the project.

So I started with the sinewave demo and integrated the code without difficulty. It was very easy then to look at the gain demo and determine how to have it only play the sound when I had the stylus on the keyboard. Finally, I looked at their MIDI demo to see how to get the pitch for the notes.

Now, I know how to calculate all of these things, and I've given talks on such, but what would be the point of using this library if I was going to ignore all of it?

So, I integrated this, added a little bit of decay to the sound and suddenly had a playable monophonic organ! (This is the same video that appears at the top, so there is no point in viewing it again if you've already seen it.) 

So there you go! There is certainly a lot left to do, but it is already equivalent to the first models of the stylophone!

Discussions