Toy Keyboard Tone Piano – Part 4

I’m continuing my series of posts seeing what I can do with a toy keyboard.  This post looks at some possible uses of the additional IO pins I freed up in part 3.

  • Part 1 provides all the details for adding an Arduino to the original toy keyboard.
  • Part 2 demonstrates the toy keyboard running the Oskitone “Scout” firmware.
  • Part 3 introduced a 74HC138 3 to 8 decoder to handle some of the keyboard IO and added a simple volume control.

I’ve start with a simple application to add pitch bend to the Oskitone code. If I think of new ones, I’ll update this post and add them in too.

Warning! I strongly recommend using old or second hand equipment for your experiments.  I am not responsible for any damage to expensive instruments!

These are the key Arduino tutorials for the main concepts used in this project:

If you are new to Arduino, see the Getting Started pages.

Free IO Pins Mapping

The following IO pins are now available for additional uses:

  • A3 to A7 (A3 to A5 if you are using an Arduino Uno)
  • RX and TX (D0 and D1)
  • D2-D3

Analog Input – Pitch Bend

The first application is to add a potentiometer to one of the analog inputs and use it for a simple pitch bend application.

For this purpose I’m adding a slider potentiometer to A3 as shown below.

IMG_5851

You can use a rotary potentiometer but it isn’t as easy to use if you do.  Eventually I want to fix a slider pot to the casing, but the ones I currently have are a little long for that, so I have some shorter ones on order.

As you can see in the photo I’ve put the slider pot onto some protoboard to make a simple “breakout” for it, just to make it easier to use.

Code wise, it just requires a few small changes in the main Scout.ino file as follows.

In the main loop() I need to read the analog value and scale it to something that will be useful later on.

// Want a value in the range -0.128 to +0.127
float pitchbend = (float)(analogRead(PB_ALG_PIN) - 512)/4000.0;

As stated in the comment, I take the analog value (0 to 1023) and first turn it into a value in the range -512 to +511 by subtracting 512.  Then I cast all this to a float to turn it into a floating point value and then divide by 4000 to turn it into a value I can then treat as a “percentage” change later on to be applied to the current playing frequency.

Then the line that updates the frequency needs to be changed from the following:

 frequency.update(notes.get(buffer.getFirst()) / 4 * pow(2, octave));

To the new line to apply the pitchbend as follows:

float targetFreq = notes.get(nextkey) / 4 * pow(2, octave);
frequency.update(targetFreq + pitchbend*targetFreq);

I take the pitchbend value as a % of the required frequency and then add it on.  This means that, if I’ve got my sums right, the frequency will always be the target frequency with a change of up to +/- ~12% depending on the setting of the potentiometer.

It seems to work out ok.  You can hear it in action in the simple video demonstration above.

Eventually, as I say, I want to build this into the casing.  I’ll update this post when I’ve decided how I’d like to do it!

Closing Thoughts

I plan to add to this post as I think of other functions to add to my Oskitone Scout clone, but really it is getting to the point where it is mostly a matter of thinking it, wiring it in and updating the code slightly.

Really, the next major advance would be to get the Arduino embedded properly into the keyboard to have it working a lot neater…

Kevin

IMG_5852

Leave a comment