# A modulo of arrays

This is a general programming question but I’m using MIDI and that’s the way I feel most comfortable describing what I’m trying to accomplish:

I have an array of potentiometer values, and a button that changes the MIDI channel. This way, multiple midi devices can be controlled by the same 16 pots. Looking to store the values of the MIDI channels that I’m not on, to retain the values once I cycle back to that channel, and so I can save all MIDI channel values at once to EEPROM from any one channel. So if I have 2 channels and 16 pots, it would save to 32 EEPROM addresses, with the values ‘frozen’ from when I left the channel.

Pretty sure I need a modulo for this, which I’ve used, but not with an array of values. More specifically I need an array of pointers? Doing something like this does not work:

``````for (int i = 0; i < 16; i++){
for(int r = 0; r < 2; r++){
channel[r] = potValue[i];
``````

So the value I’m saving to EEPROM is potValue[channel].

If there’s a better method, or a common method of accomplishing this in a different way than I’ve presented, I’m not married to the modulo idea. Thanks!

Figured out the EEPROM saving portion without using a modulo by assigning potValue to a variable for each of the channels when chosen and doing 2 sequential EEPROM updates where the second one is address + 20. Still stuck on how to make values ‘stay put’ when the array returns to that channel, so if the value of pot 1 is 10 on channel one, when I flip to channel two and back, it will be 10 still. For some reason, all the potentiometer values snap to “42” . Here’s the relevant snippet:

``````buttonState[5] = digitalRead(channelSwitch);
if(buttonState[5] != lastButtonState[5]){
if(buttonState[5] == LOW){
for(int i = 0; i < 16; i++){
potVal[i] = potChannelVal1[i];
}
}else{
if(MIDIChannel == 2){
for(int i = 0; i < 16; i++){
potVal[i] = potChannelVal2[i];
``````

You can save an entire array to EEPROM with a single use of the put() function and load it back with a single use of the get() function if that is any help. No need to calculate offsets between values

As you have not posted a complete sketch it is difficult to see your question in context