Hi,
My project is to build an efficient user interface for a DSP guitar amp modelling system.
The system can be controlled via MIDI but the program change codes look nothing like the memory location names the user sees. I.e., preset E3 = program change 18, preset V4 = program change 87.
Using an A to Z and 1 to 4 keypad will allow the me to directly enter the desired memory location.
I have a table of appropriate values for each character that will generate unique values for the program change messages. What I don't have is a way read the associated values from the table.
I've read post after post about arrays and lookup tables but none of them explain the nuts and bolts of the code to access the values.
I need to know how to get the value 16 when the E key is pressed and the value 2 when the 3 key is pressed.
Attached is my code that at least reliably returns the keypad characters.
Thank you for any and all guidance you may be able to provide.
Mark
// rig_pad_4x4_C
// mchambers 12/1/22
// trying to get lookup table working
// can print keypad characters, but not their value from the array
#include "Keypad.h"
// Constants won't change:
const byte ROWS = 4; // number of rows
const byte COLS = 4; // number of columns
char keys[ROWS][COLS] = {
{'A', 'B', 'C', 'D'},
{'E', 'F', 'G', 'H'},
{'I', 'J', 'K', 'L'},
{'1', '2', '3', '4'}
};
struct LUT {
char Key;
int Val;
} keyLUT[30] = {
{"A", 0},
{"B", 4},
{"C", 8},
{"D", 12},
{"E", 16},
{"F", 20},
{"G", 24},
{"H", 28},
{"I", 32},
{"J", 36},
{"K", 40},
{"L", 44},
{"M", 48},
{"N", 52},
{"O", 56},
{"P", 60},
{"Q", 64},
{"R", 68},
{"S", 72},
{"T", 76},
{"U", 80},
{"V", 84},
{"W", 88},
{"X", 92},
{"Y", 96},
{"Z", 100},
{"1", 0},
{"2", 1},
{"3", 2},
{"4", 3}
};
// Variables will change:
char alphaKey = 0; // 1st rig character
int numKey = 0; // 2nd rig character
// using 128 as current PC could be 0
int lastPC = 128; // previous MIDI program change value
int currentPC = 128; // current MIDI program change value
int alphaVal = 128;
int numVal = 128;
byte rowPins[ROWS] = {A0, A1, A2, A3}; // row pinouts of the keypad
byte colPins[COLS] = {2, 3, 4, 5}; // column pinouts of the keypad
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void setup()
{
Serial.begin(9600);
}
void loop()
{
char alphaKey = keypad.getKey();
if (alphaKey != NO_KEY)
Serial.println(alphaKey);
// for (int i = 0; i < 30; i++) {
// if (alphaKey == keyLUT[i].Key) {
// Serial.println(keyLUT[i].Val);
// alphaVal = (keyLUT[i].Val);
}
// }
// int numKey = keypad.getKey();
// if (numKey != NO_KEY)
// Serial.println(numKey);
// for (int i = 0; i < 30; i++) {
// if (numKey == keyLUT[i].Key) {
// Serial.println(keyLUT[i].Val);
// numVal = (keyLUT[i].Val);
// }
// }
// need to get lookup table working first
// int currentPC = alphaVal + numVal;
// if (currentPC != lastPC) {
// Serial.println(currentPC);
//}