I probably could have set it up to dump the scales array from my other arrays in a for loop, but that seemed inefficient and less flexible. So instead I decided to define my scales as something relative to a root note. Then I could create a notes array and simply grab the corresponding parts of a scale.

I kind of “over coded” by defining each scale as “whole” and “half” notes, and from there, calculating each notes deviation from the root. I could have defined all these more procedurally, but I stuck with this method, because I had already done it and it sort of makes it more readable. I tested this version out with a potentiometer to control what mode was selected.

Now it was time to get midi involved. I had worked with midi input before, but not output. I’ve never figured out how to create a software serial port while simoultaneously using Midi so there was a lot of trial and error throughout the process. Here was my first bit of code using midi:

//read all the buttons
//make sure we have midi note on
//if its the highest note, send a tone value
//if its off, send midi note off
//if no notes are on, ensure we have no tone
//questions: is it bad to repeatedly send note on or note off messages? or do I need to keep track of button states and only send on state change?

At first, this didn’t sound right. I assumed the instrument didn’t like getting repeated note on messages, so I converted my “buttons” array to a 2d array, where I would store the button’s previous state. That way I would only send note on or off when the state changed. This solved my issue immediately. YAY!

Now it was time to add my mode switching buttons.

With my mode switching buttons, I would be at a total of 15 inputs, plus a serial out, and an output for my speaker. I decided that I wanted to use a teensy for my final version since they are tiny and cheap and I wanted to get some experience with them. This is where my misery began.

Moving my project over to my Teensy LC was relatively straight forward. The buttons and tones worked as expected but I quickly ran into an issue with midi. I banged my head against the wall and couldn’t figure out what the heck was wrong. Finally I came across this forum post explaining that teensy outputs its serial over usb by default; you have to explicitly tell it to use the hardware serial port. This was helpful but I was still struggling with getting it working. Finally, I realized you could just set the serial options in arduino settings!!!! AHHHHH!! Well now it worked, but I had eaten up a ton of time.

My code was coming together, but as I added my next set of 7 buttons, I kept hitting problems. Sometimes my notes would come out wobbly. Sometimes nothing was working. Sometimes everything was working. I created a version of my program that excluded midi so I could more easily debug what was happening… And now the tone was working as expected on the teensy