Playing a TRANSPOSABLE melody on a keyboard with the Arduino

Hi everyone,

I am studying media engineering in Hamburg, Germany. We were given a cheap keyboard (music). We were asked to have the Arduino trigger notes on the keyboard and send out a MIDI signal.
Sadly we do not have much guidance and have to work a lot of things out on our own.

My group and me decided to have a melody pre-programmed on the Arduino. This worked pretty well. Our next goal is to make this melody transposable. So e.g. we have a simple triad: c, e, g. We would like to be able to read a potentiometers resistance. So when e.g. the potentiometer is turned half way the melody is transposed to: g, b, d.

Our situation is this:

  • we can play notes already. So we have that out of the way.
  • we were thinking of assigning an int number to every note. So e.g. C2 would be 0. C#2 would be 1, etc.
  • the value that the Arduino reads from the potentiometer would simply be mapped to an interval of numbers (e.g. 0 to 255 would be mapped to 0 to 7). This mapped value would then be simply added to the value of the note in the existing melody.

Our problem currently is this:

  • we had to use a matrix to send the appropriate signals to the keyboard. So every note has its own combination of row and column.

I tried this:

  • assigning variables: "int F = 2;", "int F# = 3;"
  • I did not have the opportunity to test this since I have no Arduino at home. But I hope that "var =F + 1" simply spits out "var = F#".
    Maybe you can correct me on that already?

The problem is that e.g. the F# has row 2 and column 8 assigned to it. So I need to be able to add numbers to the existing note, therefore transposing it (say F to F#). And at the same time this new calculated note needs to refer to the row and column of this new note (F#, row 2, column 8).

Here comes my question finally: do you have any idea how to approach this problem?

We would be very happy for help!

Thanks in advance,
Leonhard

The problem is that e.g. the F# has row 2 and column 8 assigned to it.

How.

It should be very simple, you have a look up table that converts a number ( your input note ) into the appropriate column and row. Then you your MIDI number as the index into that look up table.

All you then need to do it to add your transposition number to the original MIDI to get where to look up.

we were thinking of assigning an int number to every note.

You can but it is a pain and a waste of memory. How about using a #define and let the compiler do the substitution?

Thanks for that super fast reply!

I googled how to creat a lookup table with the Arduino. As far as I understood it now it is simply an array.
Do you know if it is possible to name an array with a number? My code is posted below.

int 5 = F2;
int 6 = F#2;

int 5 [2] = {2, 7};
int 6 [2] = {2, 8};

I get an error when compiling which says:

"int 6 [2] = {2, 8};

^

exit status 1
expected unqualified-id before numeric constant"

Did I not understand your suggestion with the lookup table properly?

The #define command seems like a good option.

. As far as I understood it now it is simply an array.

Yes that is how you implement one.

Do you know if it is possible to name an array with a number?

I do. It is not, it must be named like any other variable.

Did I not understand your suggestion with the lookup table properly?

Looks like it.
Use two arrays, one for row and the other for column.

You should read a bit more about the C language, allowed identifier names and declarations. This is what you could use:

const int F2 = 5;
const int Fis2 = 6;

or

typedef enum {C1, Cis1, D1, ... maxNote} Noten;

and

int row[maxNote] = {...};
int col[maxNote] = [...};

Then you can use C1 etc. as names for know notes.

Cool!
With the example code I understood what Grumpy_Mike was trying to explain to me. I am really not experienced at all with programming so thanks a lot for your suggestions and help!