Code voor midi keyboard.

algemene C code
Berichten: 7
Geregistreerd: 07 Jul 2016, 15:07

Code voor midi keyboard.

Berichtdoor spook » 07 Jul 2016, 16:07

Hallo allemaal,

Ik ben bezig met het maken van een midi keyboard met een arduino en een keyboard matrix.
Dit is een van mijn eerste projecten met een arduino dus alles is nog een beetje nieuw.
Nu heb ik al een paar testen gedaan en het werk een beetje de code is het probleem.
deze setup heb ik een beetje werkend de noten kloppen niet:
http://www.codetinkerhack.com/2012/11/h ... -midi.html

Alleen mijn keyboard bestaat uit 48 toetsen en keymatrix van 9x12.
Nu staat er op deze blog ook nog een code voor een 64 toetsen keyboard maar hier wordt ik helaas niet wijzer van.
http://www.codetinkerhack.com/2013/12/h ... board.html
De keymatrix is van een oud trg mk149 midi keyboard.
Ik hoop dat iemand mij hiermee kan helpen.

alvast bedankt

Advertisement

Gebruikers-avatar
Berichten: 5043
Geregistreerd: 13 Mei 2013, 20:57
Woonplaats: Heemskerk

Re: Code voor midi keyboard.

Berichtdoor nicoverduin » 07 Jul 2016, 16:36

Zet je sketch maar eens hier
Docent HBO Technische Informatica, Embedded ontwikkelaar & elektronicus
http://www.verelec.nl

Berichten: 7
Geregistreerd: 07 Jul 2016, 15:07

Re: Code voor midi keyboard.

Berichtdoor spook » 07 Jul 2016, 17:03

dit is de sketch die ik op dit moment gebruik.
cpp code
// Pin Definitions
// Rows are connected to
const int row1 = 5;
const int row2 = 6;
const int row3 = 7;
const int row4 = 8;

// The 74HC595 uses a serial communication
// link which has three pins
const int clock = 9;
const int latch = 10;
const int data = 11;


uint8_t keyToMidiMap[32];

boolean keyPressed[32];

int noteVelocity = 127;


// use prepared bit vectors instead of shifting bit left everytime
int bits[] = { B00000001, B00000010, B00000100, B00001000, B00010000, B00100000, B01000000, B10000000 };


// 74HC595 shift to next column
void scanColumn(int value) {
digitalWrite(latch, LOW); //Pulls the chips latch low
shiftOut(data, clock, MSBFIRST, value); //Shifts out the 8 bits to the shift register
digitalWrite(latch, HIGH); //Pulls the latch high displaying the data
}

void setup() {

// Map scan matrix buttons/keys to actual Midi note number. Lowest num 41 corresponds to F MIDI note.
keyToMidiMap[0] = 48;
keyToMidiMap[1] = 41;
keyToMidiMap[2] = 42;
keyToMidiMap[3] = 43;
keyToMidiMap[4] = 44;
keyToMidiMap[5] = 45;
keyToMidiMap[6] = 46;
keyToMidiMap[7] = 47;

keyToMidiMap[8] = 56;
keyToMidiMap[1 + 8] = 49;
keyToMidiMap[2 + 8] = 50;
keyToMidiMap[3 + 8] = 51;
keyToMidiMap[4 + 8] = 52;
keyToMidiMap[5 + 8] = 53;
keyToMidiMap[6 + 8] = 54;
keyToMidiMap[7 + 8] = 55;

keyToMidiMap[16] = 64;
keyToMidiMap[1 + 16] = 57;
keyToMidiMap[2 + 16] = 58;
keyToMidiMap[3 + 16] = 59;
keyToMidiMap[4 + 16] = 60;
keyToMidiMap[5 + 16] = 61;
keyToMidiMap[6 + 16] = 62;
keyToMidiMap[7 + 16] = 63;

keyToMidiMap[24] = 72;
keyToMidiMap[1 + 24] = 65;
keyToMidiMap[2 + 24] = 66;
keyToMidiMap[3 + 24] = 67;
keyToMidiMap[4 + 24] = 68;
keyToMidiMap[5 + 24] = 69;
keyToMidiMap[6 + 24] = 70;
keyToMidiMap[7 + 24] = 71;

// setup pins output/input mode
pinMode(data, OUTPUT);
pinMode(clock, OUTPUT);
pinMode(latch, OUTPUT);

pinMode(row1, INPUT);
pinMode(row2, INPUT);
pinMode(row3, INPUT);
pinMode(row4, INPUT);

Serial.begin(31250);

delay(1000);

}

void loop() {

for (int col = 0; col < 8; col++) {

// shift scan matrix to following column
scanColumn(bits[col]);

// check if any keys were pressed - rows will have HIGH output in this case corresponding
int groupValue1 = digitalRead(row1);
int groupValue2 = digitalRead(row2);
int groupValue3 = digitalRead(row3);
int groupValue4 = digitalRead(row4);

// process if any combination of keys pressed
if (groupValue1 != 0 || groupValue2 != 0 || groupValue3 != 0
|| groupValue4 != 0) {

if (groupValue1 != 0 && !keyPressed[col]) {
keyPressed[col] = true;
noteOn(0x91, keyToMidiMap[col], noteVelocity);
}

if (groupValue2 != 0 && !keyPressed[col + 8]) {
keyPressed[col + 8] = true;
noteOn(0x91, keyToMidiMap[col + 8], noteVelocity);
}

if (groupValue3 != 0 && !keyPressed[col + 16]) {
keyPressed[col + 16] = true;
noteOn(0x91, keyToMidiMap[col + 16], noteVelocity);
}

if (groupValue4 != 0 && !keyPressed[col + 24]) {
keyPressed[col + 24] = true;
noteOn(0x91, keyToMidiMap[col + 24], noteVelocity);
}

}

// process if any combination of keys released
if (groupValue1 == 0 && keyPressed[col]) {
keyPressed[col] = false;
noteOn(0x91, keyToMidiMap[col], 0);
}

if (groupValue2 == 0 && keyPressed[col + 8]) {
keyPressed[col + 8] = false;
noteOn(0x91, keyToMidiMap[col + 8], 0);
}

if (groupValue3 == 0 && keyPressed[col + 16]) {
keyPressed[col + 16] = false;
noteOn(0x91, keyToMidiMap[col + 16], 0);
}

if (groupValue4 == 0 && keyPressed[col + 24]) {
keyPressed[col + 24] = false;
noteOn(0x91, keyToMidiMap[col + 24], 0);
}

}

}


void noteOn(int cmd, int pitch, int velocity) {
Serial.write(cmd);
Serial.write(pitch);
Serial.write(velocity);
}

Gebruikers-avatar
Berichten: 5043
Geregistreerd: 13 Mei 2013, 20:57
Woonplaats: Heemskerk

Re: Code voor midi keyboard.

Berichtdoor nicoverduin » 07 Jul 2016, 20:23

Als de noten niet kloppen is de bedrading naar het toetsenbord wel juist? Oftewel heb je een schema van het toetsenbord en welke toets behoort bij het kruispunt van regel en kolom?
Docent HBO Technische Informatica, Embedded ontwikkelaar & elektronicus
http://www.verelec.nl

Berichten: 4067
Geregistreerd: 16 Okt 2013, 14:31
Woonplaats: s hertogenbosch

Re: Code voor midi keyboard.

Berichtdoor shooter » 07 Jul 2016, 22:48

een keymatrix van 9x12 betekent dus heel simpel dat je 9 coloms en 12 rijen hebt, en de software is maar 8x8
het kan zijn dat niet elke plaats bezet is van het keyboard natuurlijk. en dat betekent natuurlijk wel dat je de hardware moet uitbreiden.
paul deelen
shooter@home.nl

Berichten: 7
Geregistreerd: 07 Jul 2016, 15:07

Re: Code voor midi keyboard.

Berichtdoor spook » 08 Jul 2016, 11:27

Hallo alvast bedankt voor jullie reacties.

Dat de noten niet kloppen zou heel goed kunnen liggen aan de kabels inderdaad.
Hiermee ga ik later experimenteren als elke toets een signaal heeft.

Verder over de hardware ik maak gebruik van 2x een 74hc595 met elk 8 uitgangen 16 in totaal.
Dus dat is voldoende voor de 12 ingangen naar het keyboard matrix.
Alleen het probleem is wat ik lees in de sketch is dat:
const int row8 = 1;
Betekend dit dat een van de 9 signalen uit de matrix naar de 1e pin van de aruidno gaan?
Aangezien de 1e pin voorheen bedoeld is om van de aruidno naar de 5e pin te gaan op de midi poort.
al met al kan ik niet precies aflezen welke poorten op de arduino nou gebruikt worden voor uitgangen van het keyboard matrix.
cpp code
const int row8 = 1; pin 1?
const int row1 = 5; pin 5
const int row2 = 6; pin 6
const int row3 = 7; pin 7
const int row4 = 8; etc

Ik hoop dat een van jullie dit kan aflezen in de sketch.

de sketch voor de 8x8 64 noten:
cpp code
// Pin Definitions
// Rows are connected to
const int row1 = 5;
const int row2 = 6;
const int row3 = 7;
const int row4 = 8;
const int row5 = 4;
const int row6 = 3;
const int row7 = 2;
const int row8 = 1;




// The 74HC595 uses a serial communication
// link which has three pins
const int clock = 9;
const int latch = 10;
const int data = 11;


uint8_t keyToMidiMap[64];

boolean keyPressed[64];

int noteVelocity = 127;


// use prepared bit vectors instead of shifting bit left everytime
int bits[] = { B00000001, B00000010, B00000100, B00001000, B00010000, B00100000, B01000000, B10000000 };


// 74HC595 shift to next column
void scanColumn(int value) {
digitalWrite(latch, LOW); //Pulls the chips latch low
shiftOut(data, clock, MSBFIRST, value); //Shifts out the 8 bits to the shift register
digitalWrite(latch, HIGH); //Pulls the latch high displaying the data
}

void setup() {

// Map scan matrix buttons/keys to actual Midi note number. Lowest num 41 corresponds to F MIDI note.
keyToMidiMap[0] = 48;
keyToMidiMap[1] = 41;
keyToMidiMap[2] = 42;
keyToMidiMap[3] = 43;
keyToMidiMap[4] = 44;
keyToMidiMap[5] = 45;
keyToMidiMap[6] = 46;
keyToMidiMap[7] = 47;

keyToMidiMap[8] = 56;
keyToMidiMap[1 + 8] = 49;
keyToMidiMap[2 + 8] = 50;
keyToMidiMap[3 + 8] = 51;
keyToMidiMap[4 + 8] = 52;
keyToMidiMap[5 + 8] = 53;
keyToMidiMap[6 + 8] = 54;
keyToMidiMap[7 + 8] = 55;

keyToMidiMap[16] = 64;
keyToMidiMap[1 + 16] = 57;
keyToMidiMap[2 + 16] = 58;
keyToMidiMap[3 + 16] = 59;
keyToMidiMap[4 + 16] = 60;
keyToMidiMap[5 + 16] = 61;
keyToMidiMap[6 + 16] = 62;
keyToMidiMap[7 + 16] = 63;

keyToMidiMap[24] = 72;
keyToMidiMap[1 + 24] = 65;
keyToMidiMap[2 + 24] = 66;
keyToMidiMap[3 + 24] = 67;
keyToMidiMap[4 + 24] = 68;
keyToMidiMap[5 + 24] = 69;
keyToMidiMap[6 + 24] = 70;
keyToMidiMap[7 + 24] = 71;

keyToMidiMap[32] = 72;
keyToMidiMap[1 + 32] = 65;
keyToMidiMap[2 + 32] = 66;
keyToMidiMap[3 + 32] = 67;
keyToMidiMap[4 + 32] = 68;
keyToMidiMap[5 + 32] = 69;
keyToMidiMap[6 + 32] = 70;
keyToMidiMap[7 + 32] = 71;

keyToMidiMap[40] = 72;
keyToMidiMap[1 + 40] = 65;
keyToMidiMap[2 + 40] = 66;
keyToMidiMap[3 + 40] = 67;
keyToMidiMap[4 + 40] = 68;
keyToMidiMap[5 + 40] = 69;
keyToMidiMap[6 + 40] = 70;
keyToMidiMap[7 + 40] = 71;

keyToMidiMap[48] = 72;
keyToMidiMap[1 + 48] = 65;
keyToMidiMap[2 + 48] = 66;
keyToMidiMap[3 + 48] = 67;
keyToMidiMap[4 + 48] = 68;
keyToMidiMap[5 + 48] = 69;
keyToMidiMap[6 + 48] = 70;
keyToMidiMap[7 + 48] = 71;

keyToMidiMap[56] = 72;
keyToMidiMap[1 + 56] = 65;
keyToMidiMap[2 + 56] = 66;
keyToMidiMap[3 + 56] = 67;
keyToMidiMap[4 + 56] = 68;
keyToMidiMap[5 + 56] = 69;
keyToMidiMap[6 + 56] = 70;
keyToMidiMap[7 + 56] = 71;

// setup pins output/input mode
pinMode(data, OUTPUT);
pinMode(clock, OUTPUT);
pinMode(latch, OUTPUT);

pinMode(row1, INPUT);
pinMode(row2, INPUT);
pinMode(row3, INPUT);
pinMode(row4, INPUT);
pinMode(row5, INPUT);
pinMode(row6, INPUT);
pinMode(row7, INPUT);
pinMode(row8, INPUT);

Serial.begin(31250);

delay(1000);

}

void loop() {

for (int col = 0; col < 8; col++) {

// shift scan matrix to following column
scanColumn(bits[col]);

// check if any keys were pressed - rows will have HIGH output in this case corresponding
int groupValue1 = digitalRead(row1);
int groupValue2 = digitalRead(row2);
int groupValue3 = digitalRead(row3);
int groupValue4 = digitalRead(row4);
int groupValue5 = digitalRead(row5);
int groupValue6 = digitalRead(row6);
int groupValue7 = digitalRead(row7);
int groupValue8 = digitalRead(row8);

// process if any combination of keys pressed
if (groupValue1 != 0 || groupValue2 != 0 || groupValue3 != 0 || groupValue4 != 0 || groupValue5 != 0 || groupValue6 != 0 || groupValue7 != 0 || groupValue8 != 0) {

if (groupValue1 != 0 && !keyPressed[col]) {
keyPressed[col] = true;
noteOn(0x91, keyToMidiMap[col], noteVelocity);
}

if (groupValue2 != 0 && !keyPressed[col + 8]) {
keyPressed[col + 8] = true;
noteOn(0x91, keyToMidiMap[col + 8], noteVelocity);
}

if (groupValue3 != 0 && !keyPressed[col + 16]) {
keyPressed[col + 16] = true;
noteOn(0x91, keyToMidiMap[col + 16], noteVelocity);
}

if (groupValue4 != 0 && !keyPressed[col + 24]) {
keyPressed[col + 24] = true;
noteOn(0x91, keyToMidiMap[col + 24], noteVelocity);
}

if (groupValue5 != 0 && !keyPressed[col + 32]) {
keyPressed[col + 32] = true;
noteOn(0x91, keyToMidiMap[col + 32], noteVelocity);
}

if (groupValue6 != 0 && !keyPressed[col + 40]) {
keyPressed[col + 40] = true;
noteOn(0x91, keyToMidiMap[col + 40], noteVelocity);
}

if (groupValue7 != 0 && !keyPressed[col + 48]) {
keyPressed[col + 48] = true;
noteOn(0x91, keyToMidiMap[col + 48], noteVelocity);
}

if (groupValue8 != 0 && !keyPressed[col + 56]) {
keyPressed[col + 56] = true;
noteOn(0x91, keyToMidiMap[col + 56], noteVelocity);
}

}

// process if any combination of keys released
if (groupValue1 == 0 && keyPressed[col]) {
keyPressed[col] = false;
noteOn(0x91, keyToMidiMap[col], 0);
}

if (groupValue2 == 0 && keyPressed[col + 8]) {
keyPressed[col + 8] = false;
noteOn(0x91, keyToMidiMap[col + 8], 0);
}

if (groupValue3 == 0 && keyPressed[col + 16]) {
keyPressed[col + 16] = false;
noteOn(0x91, keyToMidiMap[col + 16], 0);
}

if (groupValue4 == 0 && keyPressed[col + 24]) {
keyPressed[col + 24] = false;
noteOn(0x91, keyToMidiMap[col + 24], 0);
}

if (groupValue5 == 0 && keyPressed[col + 32]) {
keyPressed[col + 32] = false;
noteOn(0x91, keyToMidiMap[col + 32], 0);
}

if (groupValue6 == 0 && keyPressed[col + 40]) {
keyPressed[col + 40] = false;
noteOn(0x91, keyToMidiMap[col + 40], 0);
}

if (groupValue7 == 0 && keyPressed[col + 48]) {
keyPressed[col + 48] = false;
noteOn(0x91, keyToMidiMap[col + 48], 0);
}

if (groupValue8 == 0 && keyPressed[col + 56]) {
keyPressed[col + 56] = false;
noteOn(0x91, keyToMidiMap[col + 56], 0);
}
}
}


void noteOn(int cmd, int pitch, int velocity) {
Serial.write(cmd);
Serial.write(pitch);
Serial.write(velocity);
}

Berichten: 4067
Geregistreerd: 16 Okt 2013, 14:31
Woonplaats: s hertogenbosch

Re: Code voor midi keyboard.

Berichtdoor shooter » 08 Jul 2016, 20:24

pin0 en pin1 niet gebruiken die zitten op de serial.
paul deelen
shooter@home.nl

Berichten: 7
Geregistreerd: 07 Jul 2016, 15:07

Re: Code voor midi keyboard.

Berichtdoor spook » 10 Jul 2016, 19:05

Hallo ik heb zelf wat geprobeerd te type met een bestaande sketch.
Is er aan de hand van de sketch nog af te lezen welke pinnen wel gebruikt worden?
hier de sketch misschien valt iemand wat verkeerds op ofzo;
cpp code
// Pin Definitions
// Rows are connected to
const int row1 = 5;
const int row2 = 6;
const int row3 = 7;
const int row4 = 8;
const int row5 = 4;
const int row6 = 3;
const int row7 = 2;
const int row8 = 13;
const int row9 = 12;




// The 74HC595 uses a serial communication
// link which has three pins
const int clock = 9;
const int latch = 10;
const int data = 11;


uint8_t keyToMidiMap[72];

boolean keyPressed[72];

int noteVelocity = 127;


// use prepared bit vectors instead of shifting bit left everytime
int bits[] = { B00000001, B00000010, B00000100, B00001000, B00010000, B00100000, B01000000, B10000000 };


// 74HC595 shift to next column
void scanColumn(int value) {
digitalWrite(latch, LOW); //Pulls the chips latch low
shiftOut(data, clock, MSBFIRST, value); //Shifts out the 8 bits to the shift register
digitalWrite(latch, HIGH); //Pulls the latch high displaying the data
}

void setup() {

// Map scan matrix buttons/keys to actual Midi note number. Lowest num 24 corresponds to C MIDI note.
keyToMidiMap[0] = 32;
keyToMidiMap[1] = 25;
keyToMidiMap[2] = 26;
keyToMidiMap[3] = 27;
keyToMidiMap[4] = 28;
keyToMidiMap[5] = 29;
keyToMidiMap[6] = 30;
keyToMidiMap[7] = 31;

keyToMidiMap[8] = 40;
keyToMidiMap[1 + 8] = 33;
keyToMidiMap[2 + 8] = 34;
keyToMidiMap[3 + 8] = 35;
keyToMidiMap[4 + 8] = 36;
keyToMidiMap[5 + 8] = 37;
keyToMidiMap[6 + 8] = 38;
keyToMidiMap[7 + 8] = 39;

keyToMidiMap[16] = 48;
keyToMidiMap[1 + 16] = 41;
keyToMidiMap[2 + 16] = 42;
keyToMidiMap[3 + 16] = 43;
keyToMidiMap[4 + 16] = 44;
keyToMidiMap[5 + 16] = 45;
keyToMidiMap[6 + 16] = 46;
keyToMidiMap[7 + 16] = 47;

keyToMidiMap[24] = 56;
keyToMidiMap[1 + 24] = 49;
keyToMidiMap[2 + 24] = 50;
keyToMidiMap[3 + 24] = 51;
keyToMidiMap[4 + 24] = 52;
keyToMidiMap[5 + 24] = 53;
keyToMidiMap[6 + 24] = 54;
keyToMidiMap[7 + 24] = 55;

keyToMidiMap[32] = 64;
keyToMidiMap[1 + 32] = 57;
keyToMidiMap[2 + 32] = 58;
keyToMidiMap[3 + 32] = 59;
keyToMidiMap[4 + 32] = 60;
keyToMidiMap[5 + 32] = 61;
keyToMidiMap[6 + 32] = 62;
keyToMidiMap[7 + 32] = 63;

keyToMidiMap[40] =72;
keyToMidiMap[1 + 40] = 65;
keyToMidiMap[2 + 40] = 66;
keyToMidiMap[3 + 40] = 67;
keyToMidiMap[4 + 40] = 68;
keyToMidiMap[5 + 40] = 69;
keyToMidiMap[6 + 40] = 70;
keyToMidiMap[7 + 40] = 71;

keyToMidiMap[48] =80;
keyToMidiMap[1 + 48] = 73;
keyToMidiMap[2 + 48] = 74;
keyToMidiMap[3 + 48] = 75;
keyToMidiMap[4 + 48] = 76;
keyToMidiMap[5 + 48] = 77;
keyToMidiMap[6 + 48] = 78;
keyToMidiMap[7 + 48] = 79;

keyToMidiMap[56] = 88;
keyToMidiMap[1 + 56] = 81;
keyToMidiMap[2 + 56] = 82;
keyToMidiMap[3 + 56] = 83;
keyToMidiMap[4 + 56] = 84;
keyToMidiMap[5 + 56] = 85;
keyToMidiMap[6 + 56] = 86;
keyToMidiMap[7 + 56] = 87;

keyToMidiMap[64] = 96;
keyToMidiMap[1 + 64] = 89;
keyToMidiMap[2 + 64] = 90;
keyToMidiMap[3 + 64] = 91;
keyToMidiMap[4 + 64] = 92;
keyToMidiMap[5 + 64] = 93;
keyToMidiMap[6 + 64] = 94;
keyToMidiMap[7 + 64] = 95;

// setup pins output/input mode
pinMode(data, OUTPUT);
pinMode(clock, OUTPUT);
pinMode(latch, OUTPUT);

pinMode(row1, INPUT);
pinMode(row2, INPUT);
pinMode(row3, INPUT);
pinMode(row4, INPUT);
pinMode(row5, INPUT);
pinMode(row6, INPUT);
pinMode(row7, INPUT);
pinMode(row8, INPUT);
pinMode(row9, INPUT);

Serial.begin(31250);

delay(1000);

}

void loop() {

for (int col = 0; col < 8; col++) {

// shift scan matrix to following column
scanColumn(bits[col]);

// check if any keys were pressed - rows will have HIGH output in this case corresponding
int groupValue1 = digitalRead(row1);
int groupValue2 = digitalRead(row2);
int groupValue3 = digitalRead(row3);
int groupValue4 = digitalRead(row4);
int groupValue5 = digitalRead(row5);
int groupValue6 = digitalRead(row6);
int groupValue7 = digitalRead(row7);
int groupValue8 = digitalRead(row8);
int groupValue9 = digitalRead(row9);


// process if any combination of keys pressed
if (groupValue1 != 0 || groupValue2 != 0 || groupValue3 != 0 || groupValue4 != 0 || groupValue5 != 0 || groupValue6 != 0 || groupValue7 != 0 || groupValue8 != 0) {

if (groupValue1 != 0 && !keyPressed[col]) {
keyPressed[col] = true;
noteOn(0x91, keyToMidiMap[col], noteVelocity);
}

if (groupValue2 != 0 && !keyPressed[col + 8]) {
keyPressed[col + 8] = true;
noteOn(0x91, keyToMidiMap[col + 8], noteVelocity);
}

if (groupValue3 != 0 && !keyPressed[col + 16]) {
keyPressed[col + 16] = true;
noteOn(0x91, keyToMidiMap[col + 16], noteVelocity);
}

if (groupValue4 != 0 && !keyPressed[col + 24]) {
keyPressed[col + 24] = true;
noteOn(0x91, keyToMidiMap[col + 24], noteVelocity);
}

if (groupValue5 != 0 && !keyPressed[col + 32]) {
keyPressed[col + 32] = true;
noteOn(0x91, keyToMidiMap[col + 32], noteVelocity);
}

if (groupValue6 != 0 && !keyPressed[col + 40]) {
keyPressed[col + 40] = true;
noteOn(0x91, keyToMidiMap[col + 40], noteVelocity);
}

if (groupValue7 != 0 && !keyPressed[col + 48]) {
keyPressed[col + 48] = true;
noteOn(0x91, keyToMidiMap[col + 48], noteVelocity);
}

if (groupValue8 != 0 && !keyPressed[col + 56]) {
keyPressed[col + 56] = true;
noteOn(0x91, keyToMidiMap[col + 56], noteVelocity);
}

if (groupValue9 != 0 && !keyPressed[col + 64]) {
keyPressed[col + 64] = true;
noteOn(0x91, keyToMidiMap[col + 64], noteVelocity);
}

}

// process if any combination of keys released
if (groupValue1 == 0 && keyPressed[col]) {
keyPressed[col] = false;
noteOn(0x91, keyToMidiMap[col], 0);
}

if (groupValue2 == 0 && keyPressed[col + 8]) {
keyPressed[col + 8] = false;
noteOn(0x91, keyToMidiMap[col + 8], 0);
}

if (groupValue3 == 0 && keyPressed[col + 16]) {
keyPressed[col + 16] = false;
noteOn(0x91, keyToMidiMap[col + 16], 0);
}

if (groupValue4 == 0 && keyPressed[col + 24]) {
keyPressed[col + 24] = false;
noteOn(0x91, keyToMidiMap[col + 24], 0);
}

if (groupValue5 == 0 && keyPressed[col + 32]) {
keyPressed[col + 32] = false;
noteOn(0x91, keyToMidiMap[col + 32], 0);
}

if (groupValue6 == 0 && keyPressed[col + 40]) {
keyPressed[col + 40] = false;
noteOn(0x91, keyToMidiMap[col + 40], 0);
}

if (groupValue7 == 0 && keyPressed[col + 48]) {
keyPressed[col + 48] = false;
noteOn(0x91, keyToMidiMap[col + 48], 0);
}

if (groupValue8 == 0 && keyPressed[col + 56]) {
keyPressed[col + 56] = false;
noteOn(0x91, keyToMidiMap[col + 56], 0);
}

if (groupValue9 == 0 && keyPressed[col + 64]) {
keyPressed[col + 64] = false;
noteOn(0x91, keyToMidiMap[col + 64], 0);
}
}
}


void noteOn(int cmd, int pitch, int velocity) {
Serial.write(cmd);
Serial.write(pitch);
Serial.write(velocity);
}

Berichten: 4067
Geregistreerd: 16 Okt 2013, 14:31
Woonplaats: s hertogenbosch

Re: Code voor midi keyboard.

Berichtdoor shooter » 10 Jul 2016, 22:30

zet eens een serial.print neer zodat je weet welke colom aan staat en welke rij er bij aan is, als je een toets indrukt.
en maak eens een verbinding tussen een rij en een colom, dan weet je of de software klopt.
zitten er diodes in de toetsen? en heb je het dan goed aangesloten.
paul deelen
shooter@home.nl

Berichten: 7
Geregistreerd: 07 Jul 2016, 15:07

Re: Code voor midi keyboard.

Berichtdoor spook » 11 Jul 2016, 14:40

Hallo
ik heb zojuist gekeken naar de diodes in de matrix en deze werken allemaal en de bedrading werk ook nog.
De rest van dingen zal ik zo snel mogelijk testen als alles weer in elkaar zit.
Wat mij opviel is dat het keyboard matrix twee signalen krijgt per toets ik zal dit proberen in kaart te brengen.

Volgende

Terug naar C code

Wie is er online?

Gebruikers in dit forum: Geen geregistreerde gebruikers en 15 gasten