Predefined int matrix to update via serial from Processing

Hi,

I am working on a midi controller project. The controller has a preset mode. When a preset is selected it gets the button states predefined in prsBtState variable and updates the current butoon states.

The prsBtState state variable is a 20x8 int matrix.

int prsBtState[20][8] ={
                          {1, 0, 0, 0, 0, 0, 0, 0},//A1
                          {0, 1, 0, 0, 0, 0, 0, 0},//A2
                          {0, 0, 1, 0, 0, 0, 0, 0},//A3
                          {0, 0, 0, 1, 0, 0, 0, 0},//A4
                          {0, 0, 0, 0, 1, 0, 0, 0},//B1
                          {0, 0, 0, 0, 0, 1, 0, 0},//B2
                          {0, 0, 0, 0, 0, 0, 1, 0},//B3
                          {0, 0, 0, 0, 0, 0, 0, 1},//B4
                          {0, 1, 0, 1, 0, 1, 0, 1},//C1
                          {1, 1, 1, 1, 1, 1, 1, 1},//C2
                          {0, 0, 0, 0, 0, 0, 0, 0},//C3
                          {1, 0, 1, 0, 1, 0, 1, 0},//C4
                          {1, 1, 1, 1, 1, 1, 1, 1},//D1
                          {0, 0, 0, 0, 0, 0, 0, 0},//D2
                          {1, 0, 1, 0, 1, 0, 1, 0},//D3
                          {0, 1, 0, 1, 0, 1, 0, 1},//D4
                          {0, 0, 0, 0, 0, 0, 0, 0},//E1
                          {1, 0, 1, 0, 1, 0, 1, 0},//E2
                          {0, 1, 0, 1, 0, 1, 0, 1},//E3
                          {1, 1, 1, 1, 1, 1, 1, 1}//E4
                          };

The current sketch is working perfect. However each time I want update the predefined presets I need to change the sketch and recompile it. Now I want to build a custom GUI (I am planning to use processing) to update the presets. The goal is send the preset updates via serial to arduino and update the prsBtState. I think I need to store prsBtState in the EEPROM in order to achive this.

I am correct; how can I store this int matrix in EERPOM?
I am wrong; what is the best way to achive my goal?

Thanks in advance.

Take a look at the values in the array. Then, explain why the array type is int.

The button state values are declared as int. The a preset is loaded i read the corresponded values from the matrix and update the button state variable with it.

Is it wrong? Shall I use another data type?

They are only 1s and 0s. They can easily be stored as bytes which will halve the storage requirement.

If your programming skills are a little more advanced you could store 8 of them as bits in a single byte.

You can store the data in the EEPROM but be conscious that there is a limit to how many times you can write data to the EEPROM.

...R

Thanks. I got your point and updated the code to change the data type to byte.

Thanks. I got your point and updated the code to change the data type to byte.

OK. So, there are three parts to your problem.

  1. Reading the data from the serial port.
  2. Storing the data in EEPROM.
  3. Retrieving the data from EEPROM.

Having changed the data type, the last two will be much easier.

Which part(s) do you need help with?

I am confused about writing and reading matrix variables from EEPROM. I have read & write single values before but never did it with matrix.

But my main confusion is about the write order. As I said I have predifened values but these values should be updateable later on. If I write these predefined values to EEPROM at the setup loop it will reset the updates at each restart. Should I compile the skecth two times? First to upload the predifed values to EEPROM with EEPROM.write() in setup and then remove the write command and change it EEPROM.read() to retrive the data stored in the EEPROM?

C doesn't really have a multi-dimensional array. What is has is an array of arrays. You can write the data in the array to EEPROM in row-major order or column-major order, whichever is easiest for you to visualize. Just make sure that you read the data in the same order.

If I write these predefined values to EEPROM at the setup loop it will reset the updates at each restart.

But, you would only write them if there were new values coming from the serial port.

It is more clear now. Then just need to convert the multi-dimensional matrix to one single matrix. If I get it correct the following calculation would give me the location address to read or write of the value I want.

prsBtState[x][y];
address = (x * 8) - (8 - y) - 1;

Then just need to convert the multi-dimensional matrix to one single matrix.

Aren't you using "matrix' to mean two dimensional array? Isn't that a multi-dimensional array? As in more than one dimension.