MIDI notes from keyboard

Hi,

I’m trying to use an old keypad keyboard as a midi keyboard.
I have got it working in a 5x8 matrix with two 4051’s, and it now prints decimals 1-40.
Because of the layout of the matrix in the old keypad, the keys I want to use as a midi piano are not in succession.
C1=11, C1#=13, D1=19 etc.
What I want is to insert some kind of table where I can say that when key 11 is pressed, print MIDI NOTE 24 etc.

here is the code I use for reading the keyboard:
It is made by this guy: nerdcore.eu

int v=0;

void setup() {
Serial.begin(9600);
Serial.print("Hello");
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,INPUT);

}

byte bin[] = {
0,1,10,11,100,101,110,111};

int readKeyboard() {
int i,j,row,col,v, code;
byte r0,r1,r2;

code=0;
for(i=0;i<5;i++) {
for(j=0;j<8;j++) {
code++;
// address X
row = bin[j];
r0 = row & 0x01;
r1 = (row>>1) & 0x01;
r2 = (row>>2) & 0x01;
digitalWrite(2, r0);
digitalWrite(3, r1);
digitalWrite(4, r2);
// address Y
col = bin[i];
r0 = col & 0x01;
r1 = (col>>1) & 0x01;
r2 = (col>>2) & 0x01;
digitalWrite(5, r0);
digitalWrite(6, r1);
digitalWrite(7, r2);

// Read the actual Value
v = digitalRead(8);

/*
Serial.print("(");
Serial.print(j);
Serial.print(":");
Serial.print(i);
Serial.print(")-");
Serial.println(v);
*/

if(v==LOW) {
// instead of returning, you may use a buffer or whatever to keep track of all pressed keys
return code;
}
}
}
}

void loop() {
v = readKeyboard();
if(v>1) {
Serial.println(v);
}

delay(100);
}

this is the other code I want to use it with
it is converting midi in signals to CV/Gate for the Gakken SX-150 synth
its from this guy: mrbook.org

#define DATAOUT 11//MOSI
#define DATAIN 12//MISO - not used, but part of builtin SPI
#define SPICLOCK  13//sck
#define SLAVESELECT 10//ss
int ledPin = 3;                // LED connected to digital pin 3
int action=2; //0 =note off ; 1=note on ; 2= nada
byte incomingByte;
byte note;
byte velocity;
int notesPushed = 0;


void setup()                    // run once, when the sketch starts
{
  //pinMode(ledPin, OUTPUT);      // sets the digital pin as output
  
  // Control Voltage Section
  byte clr;
  pinMode(DATAOUT, OUTPUT);
  pinMode(DATAIN, INPUT);
  pinMode(SPICLOCK,OUTPUT);
  pinMode(SLAVESELECT,OUTPUT);
  digitalWrite(SLAVESELECT,HIGH); //disable device
  
  SPCR = (1<<SPE)|(1<<MSTR);
  //SPCR = B01010000;
  clr=SPSR;
  clr=SPDR;
  delay(10);
  
  // MIDI Receiving Section
  //start serial with midi baudrate 31250 or 38400 for debugging
  Serial.begin(31250);
}

void write_value(uint16_t sample)
{
  uint8_t dacSPI0 = 0;
  uint8_t dacSPI1 = 0;
  dacSPI0 = (sample >> 8) & 0x00FF;
  dacSPI0 |= 0x10;
  dacSPI1 = sample & 0x00FF;
  digitalWrite(SLAVESELECT,LOW);

  SPDR = dacSPI0;                    // Start the transmission
  while (!(SPSR & (1<<SPIF)))     // Wait the end of the transmission
  {
  };
  
  SPDR = dacSPI1;
  while (!(SPSR & (1<<SPIF)))     // Wait the end of the transmission
  {
  };  
  digitalWrite(SLAVESELECT,HIGH);
  //delay(5);
}

void playNote(int incomingByte)
{
  int diff = 48 - incomingByte;
  diff *= 12;
  write_value (1125 - diff);
  // 1270 C4 60
  // 1125 C3 48
  // 980  C2 36    
  // 835  C1 24 
  // 690  C0 12      
}
void noteOff()
{
  write_value(0);
}

void playMidiNote(byte note, byte velocity){
  
  int value=LOW;
  if (velocity >0){
      value=HIGH;
  }else{
   value=LOW;
  }
  //digitalWrite(ledPin, value);
  
  if(value==HIGH){
    notesPushed++;
    playNote(note);
    analogWrite(ledPin, 255);
  }else{
    notesPushed--;
    if(notesPushed < 0) notesPushed = 0;
    if(notesPushed == 0){
      noteOff();
      analogWrite(ledPin, 0);
    }
  }
  
 
}

int potValue;

void loop()
{
/*
  potValue = (int)( ((1023 - analogRead(0)) / 1023.0) * 255);
  analogWrite(ledPin, potValue);
*/
  while (Serial.available() > 0) {
    // read the incoming byte:
    incomingByte = Serial.read();

    // wait for as status-byte, channel 1, note on or off
    if (incomingByte== 144){ // note on message starting starting
      action=1;
    }
    
    else if (incomingByte== 128){ // note off message starting
      action=0;
    }else if ( (action==0)&&(note==0) ){ // if we received a "note off", we wait for which note (databyte)
      note=incomingByte;
      playMidiNote(note, 0);
      note=0;
      velocity=0;
      action=2;
    }
            
    else if ( (action==1)&&(note==0) ){ // if we received a "note on", we wait for the note (databyte)
      note=incomingByte;
    }else if ( (action==1)&&(note!=0) ){ // ...and then the velocity
      velocity=incomingByte;
      playMidiNote(note, velocity);
      note=0;
      velocity=0;
      action=2;
    }
  }

}

void blink()
{
  digitalWrite(ledPin, HIGH);
  delay(30);
  digitalWrite(ledPin, LOW);
  delay(30);
  
   digitalWrite(ledPin, HIGH);
  delay(30);
  digitalWrite(ledPin, LOW);
  delay(30);
 
}

I’m quite new to this, and would apreciate some direction and tips
I have looked around allready, but I might be using the wrong terminology

cheers

sorry for the unclear post

I guess the question is how to write this conversion table and where to put it

I guess the question is how to write this conversion table and where to put it

You put it in an array, with the index of the array corresponding to the input value and the contents of the array at that index being the value you want to output. So if you had a key number called 'key', a conversion array called 'convert' you would get the MIDI note by doing:- midiNote = convert[key];

here is the conversion table:

11 24
13 25
19 26
21 27
27 28
35 29
37 30
33 31
34 32
25 33
26 34
17 35
9  36
15 36
24 37
23 38
32 39
31 40
39 41
38 42
36 43
30 44
28 45
22 46
20 47
12 48

the first number is the read from the key press and the second the midi note number

thanks for helping

You put it in an array, with the index of the array corresponding to the input value and the contents of the array at that index being the value you want to output. So if you had a key number called 'key', a conversion array called 'convert' you would get the MIDI note by doing:- midiNote = convert[key];

would this work when the conversion numbers are not in succession?

would this work when the conversion numbers are not in succession?

You don't get it do you.

You order them so as to make them consecutive numbers, you can even take of an offset if you like or have blank entries where you will no there is no input.