Ok, I have successfully gotten the buttons to send midi noteon/off messages and have realized that I need an LED matrix to control the lights. My controller has potentiometers on it and I can even successfully read and send midi cc messages, but it creates a constantly running read of the potentiometer state and I can’t use any of the buttons. Any thoughts (see code below),
#include <Keypad.h>
byte val = 0;
int vol = A0;
const byte ROWS = 4;
const byte COLS = 4;
char keys [ROWS][COLS] = {
{‘1’,‘2’,‘3’,‘A’},
{‘4’,‘5’,‘6’,‘B’},
{‘7’,‘8’,‘9’,‘C’},
{‘#’,‘0’,‘*’,‘D’}
};
byte rowPins [ROWS] = {11,10,9,8};
byte colPins [COLS] = {2,3,4,5};
Keypad kpd = Keypad(makeKeymap(keys),rowPins,colPins,ROWS,COLS);
void setup()
{
Serial.begin(115200);
kpd.addEventListener(keypadEvent);
}
void loop(){
char key = kpd.getKey();
if(key) {
}
val = analogRead(vol);
MIDImessage(0xB0, 7, val);
}
void keypadEvent(KeypadEvent key){
switch(kpd.getState()){
case PRESSED:
if (key == ‘1’) {
MIDImessage(0x90, 60, 127);}
break;
case RELEASED:
if (key == ‘1’) {
MIDImessage(0x80, 60, 0);}
break;
}
switch(kpd.getState()){
case PRESSED:
if (key == ‘2’) {
MIDImessage(0x91, 61, 127);}
break;
case RELEASED:
if (key == ‘2’) {
MIDImessage(0x81, 61, 0);}
break;
}
switch(kpd.getState()){
case PRESSED:
if (key == ‘3’) {
MIDImessage(0x92, 62, 127);}
break;
case RELEASED:
if (key == ‘3’) {
MIDImessage(0x82, 62, 0);}
break;
}
switch(kpd.getState()){
case PRESSED:
if (key == ‘A’) {
MIDImessage(0x93, 63, 127);}
break;
case RELEASED:
if (key == ‘A’) {
MIDImessage(0x83, 63, 0);}
break;
}
switch(kpd.getState()){
case PRESSED:
if (key == ‘4’) {
MIDImessage(0x94, 64, 127);}
break;
case RELEASED:
if (key == ‘4’) {
MIDImessage(0x84, 64, 0);}
break;
}
switch(kpd.getState()){
case PRESSED:
if (key == ‘5’) {
MIDImessage(0x95, 65, 127);}
break;
case RELEASED:
if (key == ‘5’) {
MIDImessage(0x85, 65, 0);}
break;
}
switch(kpd.getState()){
case PRESSED:
if (key == ‘6’) {
MIDImessage(0x96, 66, 127);}
break;
case RELEASED:
if (key == ‘6’) {
MIDImessage(0x86, 66, 0);}
break;
}
switch(kpd.getState()){
case PRESSED:
if (key == ‘B’) {
MIDImessage(0x97, 67, 127);}
break;
case RELEASED:
if (key == ‘B’) {
MIDImessage(0x87, 67, 0);}
break;
}
switch(kpd.getState()){
case PRESSED:
if (key == ‘7’) {
MIDImessage(0x98, 68, 127);}
break;
case RELEASED:
if (key == ‘7’) {
MIDImessage(0x88, 68, 0);}
break;
}
switch(kpd.getState()){
case PRESSED:
if (key == ‘8’) {
MIDImessage(0x99, 69, 127);}
break;
case RELEASED:
if (key == ‘8’) {
MIDImessage(0x89, 69, 0);}
break;
}
switch(kpd.getState()){
case PRESSED:
if (key == ‘9’) {
MIDImessage(0x9A, 70, 127);}
break;
case RELEASED:
if (key == ‘9’) {
MIDImessage(0x8A, 70, 0);}
break;
}
switch(kpd.getState()){
case PRESSED:
if (key == ‘C’) {
MIDImessage(0x9B, 71, 127);}
break;
case RELEASED:
if (key == ‘C’) {
MIDImessage(0x8B, 71, 0);}
break;
}
switch(kpd.getState()){
case PRESSED:
if (key == ‘#’) {
MIDImessage(0x9C, 72, 127);}
break;
case RELEASED:
if (key == ‘#’) {
MIDImessage(0x8C, 72, 0);}
break;
}
switch(kpd.getState()){
case PRESSED:
if (key == ‘0’) {
MIDImessage(0x9D, 73, 127);}
break;
case RELEASED:
if (key == ‘0’) {
MIDImessage(0x8D, 73, 0);}
break;
}
switch(kpd.getState()){
case PRESSED:
if (key == ‘*’) {
MIDImessage(0x9E, 74, 127);}
break;
case RELEASED:
if (key == ‘*’) {
MIDImessage(0x8E, 74, 0);}
break;
}
switch(kpd.getState()){
case PRESSED:
if (key == ‘D’) {
MIDImessage(0x9F, 75, 127);}
break;
case RELEASED:
if (key == ‘#’) {
MIDImessage(0x8F, 75, 0);}
break;
}
}
void MIDImessage(byte command, byte data1, byte data2) {
Serial.write(command);
Serial.write(data1);
Serial.write(data2);
}