Selecting different arrays to send to a function?

Hi all,

I am writing some code for a voltage quantizer and am stuck thinking there must be a better way to do what I am attempting to do.

My current code (which does work), looks like this.

void setStepDown()          
{
  byte a = seqNote[writeNum];
  switch (quantizerScale)
  {

    case  0: //minor
      {
        if (seqNote[writeNum] > 0)  
        {
          byte b = minTable[a - 1];     //this array is different in each case

          for (int i = 1; a == b; i++)
          {
            b = minTable[a - i];           //and here
          }
          seqNote[writeNum] = b;
        }
      }
      break;

    case  1: //major
      {
        if (seqNote[writeNum] > 0)  
        {
          byte b = majTable[a - 1];     //only thing different in each case

          for (int i = 1; a == b; i++)       
          {
            b = majTable[a - i];
          }
          seqNote[writeNum] = b;
        }
      }
      break;
}

This is actually just a short example, there are actually 8 different cases all which repeat the same code but with a different array "xxxTable" in each one.

This seems kind of pointless and messy.
It seems like better code would be to just write the function once and then send the different arrays to it as an argument
So something like this

void setStepDown(byte scale[])
{   
  byte a = seqNote[writeNum];
  if (seqNote[writeNum] > 0)  
  {
    byte b = scale[a - 1];

    for (int i = 1; a == b; i++)
    {
      b = scale[a - i];
    }
    seqNote[writeNum] = b;
  }
}

And this works, except that I am using a variable with the value of 0-7 to determine which xxxTable is being used, so when I call the function

setStepDown(xxxTable);

I can't figure out how to change the array that is sent to the function without doing something like creating another switch case and putting a different version of the function in each one.

I hope what I am asking is clear. I will do my best to answer any questions If this is confusing.

I'm pretty much self taught when it comes to programming so I suspect there is something that I am overlooking or haven't been introduced to.

Thanks in advance.

  • send a pointer to the array
    or
  • use a 2 dimentional array - send one byte to select part of array