The project is a MIDI controller. It has 6 buttons. The user can configure up to 6 MIDI commands to be sent by each button. In addition, the controller has 12 virtual banks which load each button with a new set of MIDI commands. Each command is saved in external EEPROM as an 8-byte array.
Picture of prototype:
Eventually the MIDI controller will have some sort of interface for configuration, but in the meantime, I am using a separate Arduino sketch to update the EEPROM when a configuration change is required. There isn't enough flash memory to do both in one sketch. So the EEPROM-load sketch is loaded to the controller when the configuration requires updating. Otherwise the MIDI controller sketch is loaded for actual use of the device.
The desired scenario is that the source code is formatted in a fashion that makes it easy to navigate to the right button and update the right 8-byte array.
Example:
/*pseudo code for conceptual purposes. Not intended to compile */
const int numPages = 12;
const int numButtons = 6;
const int numActions = 6;
byte b[numPages][numButtons][numActions];
//================================================ PAGE 1 ===============================================
p = 1;
/*-------Top Left ------------- ---------Top Middle------------ ---------Top Right------------*/
b[p][4][1] = {PC,0,BS,0,0,0,0,0}; b[p][5][1] = {PC,1,HX,0,0,0,0,0}; b[p][6][1] = {PC,2,HX,0,0,0,0,0};
b[p][4][2] = {PC,0,HX,0,0,0,0,0}; b[p][5][2] = {PC,2,TL,0,0,0,0,0}; b[p][6][2] = {PC,4,TL,0,0,0,0,0};
b[p][4][3] = {PC,0,TL,0,0,0,0,0} b[p][5][3] = {PC,3,BS,0,0,0,0,0}; b[p][6][3] = {PC,6,BS,0,0,0,0,0};
b[p][4][4] = {XX,0,0,0,0,0,0,0}; b[p][5][4] = {XX,0,0,0,0,0,0,0}; b[p][6][4] = {XX,0,0,0,0,0,0,0};
b[p][4][5] = {XX,0,0,0,0,0,0,0}; b[p][5][5] = {XX,0,0,0,0,0,0,0}; b[p][6][5] = {XX,0,0,0,0,0,0,0};
b[p][4][6] = {XX,0,0,0,0,0,0,0}; b[p][5][6] = {XX,0,0,0,0,0,0,0}; b[p][6][6] = {XX,0,0,0,0,0,0,0};
/*-------Bottom Left----------- ---------Bottom Middle---------- ---------Bottom Right---------*/
b[p][1][1] = {XX,0,0,0,0,0,0,0}; b[p][2][1] = {XX,0,0,0,0,0,0,0}; b[p][3][1] = {XX,0,0,0,0,0,0,0};
b[p][1][2] = {XX,0,0,0,0,0,0,0}; b[p][2][2] = {XX,0,0,0,0,0,0,0}; b[p][3][2] = {XX,0,0,0,0,0,0,0};
b[p][1][3] = {XX,0,0,0,0,0,0,0}; b[p][2][3] = {XX,0,0,0,0,0,0,0}; b[p][3][3] = {XX,0,0,0,0,0,0,0};
b[p][1][4] = {XX,0,0,0,0,0,0,0}; b[p][2][4] = {XX,0,0,0,0,0,0,0}; b[p][3][4] = {XX,0,0,0,0,0,0,0};
b[p][1][5] = {XX,0,0,0,0,0,0,0}; b[p][2][5] = {XX,0,0,0,0,0,0,0}; b[p][3][5] = {XX,0,0,0,0,0,0,0};
b[p][1][6] = {XX,0,0,0,0,0,0,0}; b[p][2][6] = {XX,0,0,0,0,0,0,0}; b[p][3][6] = {XX,0,0,0,0,0,0,0};
//================================================ PAGE 2 ===============================================
p = 2;
/*-------Top Left ------------- ---------Top Middle------------ ---------Top Right------------*/
b[p][4][1] = {PC,3,HX,0,0,0,0,0}; b[p][5][1] = {PC,4,HX,0,0,0,0,0}; b[p][6][1] = {PC, 5,HX,0,0,0,0,0};
b[p][4][2] = {PC,6,TL,0,0,0,0,0}; b[p][5][2] = {PC,8,TL,0,0,0,0,0}; b[p][6][2] = {PC,10,TL,0,0,0,0,0};
b[p][4][3] = {PC,9,BS,0,0,0,0,0}; b[p][5][3] = {PC,12,BS,0,0,0,0,0}; b[p][6][3] = {PC,15,BS,0,0,0,0,0};
b[p][4][4] = {XX,0,0,0,0,0,0,0}; b[p][5][4] = {XX,0,0,0,0,0,0,0}; b[p][6][4] = {XX,0,0,0,0,0,0,0};
b[p][4][5] = {XX,0,0,0,0,0,0,0}; b[p][5][5] = {XX,0,0,0,0,0,0,0}; b[p][6][5] = {XX,0,0,0,0,0,0,0};
b[p][4][6] = {XX,0,0,0,0,0,0,0}; b[p][5][6] = {XX,0,0,0,0,0,0,0}; b[p][6][6] = {XX,0,0,0,0,0,0,0};
/*-------Bottom Left----------- ---------Bottom Middle---------- ---------Bottom Right---------*/
b[p][1][1] = {XX,0,0,0,0,0,0,0}; b[p][2][1] = {XX,0,0,0,0,0,0,0}; b[p][3][1] = {XX,0,0,0,0,0,0,0};
b[p][1][2] = {XX,0,0,0,0,0,0,0}; b[p][2][2] = {XX,0,0,0,0,0,0,0}; b[p][3][2] = {XX,0,0,0,0,0,0,0};
b[p][1][3] = {XX,0,0,0,0,0,0,0}; b[p][2][3] = {XX,0,0,0,0,0,0,0}; b[p][3][3] = {XX,0,0,0,0,0,0,0};
b[p][1][4] = {XX,0,0,0,0,0,0,0}; b[p][2][4] = {XX,0,0,0,0,0,0,0}; b[p][3][4] = {XX,0,0,0,0,0,0,0};
b[p][1][5] = {XX,0,0,0,0,0,0,0}; b[p][2][5] = {XX,0,0,0,0,0,0,0}; b[p][3][5] = {XX,0,0,0,0,0,0,0};
b[p][1][6] = {XX,0,0,0,0,0,0,0}; b[p][2][6] = {XX,0,0,0,0,0,0,0}; b[p][3][6] = {XX,0,0,0,0,0,0,0};
/* continues for ~12 pages */
void setButton(int page, int button, int actionNum, byte action[8]){
page--; //zero-based index to 1-based convention
button--;
actionNum--;
/* Calculate the address to write the configuration to */
int addr = 0
+ (page * BytesPerPage)
+ (button * BytesPerButton)
+ (actionNum * BytesPerAction);
/* Write the configuration to external EEPROM */
int status = eep.write(addr, action, 8);
}
void setup(void)
{
//Loop through pages
for (p=1; p<=numPaged; p++){
//Loop through buttons
for (int b=1; b <=numButtons;b++){
//Loop through button actions
for (a=1; a<=numActions; a++){
setButton(p, b, a, b[p][b][a]); //Write the button config to external EEPROM
}
}
}
}
void loop(){
}
Of course this doesn't work because C doesn't allow setting arrays like this outside of the initial declaration. What are some other options for accomplishing the task.
For reference, the MIDI controller code is here, still very much a work in progress: