Beginner trouble with coding MIDI transpose function (actually more Arduino code

I'll look into and try the posted code, I started making a simpler version taking the things I myself wrote in the code and throwing the other "collected example" code away. I think my music equipment knowledge is higher than my coding, I know what math to do but I can't get the numbers to talk with each other I guess.

The project is based/inspired by the earliest of synths mellotron (it played a tape in a loop for each note), I want to combine that idea with a MIDI device/station idea (the arduino) which would be controlled by my hardware (the buttons etc) that triggers "built in" sound samples (on SD card I guess will be the first prototype). To get the old time sound the samples (triggered by midi) will be sent to a cassette recorder head and the signal will then be ran back into a speaker (or whatever audio input/output) to get the mellotron vibe. cassette motor will be controlled by arduino to achieve different effects (I have this working). I want to implement different midi patterns and chords because I want it to be kind of like a pocket orchestra that is used to write songs in a portable way but it should also be compatible with other midi devices or instruments, I also want to take advantage of the BLE technology and all the new tech things I've learnt from buying these things thru years and want to make them more available for others (code is cheaper than hardware) for example you could also be able to send sustain commands or arpeggios to other devices (or midi clock / time code).

I know this won't be achieved in three days but I was hoping at least I would be able to get somewhere in this simple code, I think It just calls for a few days break than start on it again. It will probably take forever since it feels like a never ending project. But all in all it is just math right, so once you have made the main code and understand it than it should be easy to build other modifications like arpeggios. Also I have not done any coding since I was 13 years old when I was learning javascript so I think its gonna tak e a while. I started writing a simpler code but its frustrating knowing I will have to replace it later to make it faster or less "latency" and better.

Thanks for replies