Go Down

Topic: Switch() case using arrays (Read 309 times) previous topic - next topic

Benry

Hi, I'm trying to use switch()case and I want the variable in switch to be an array. (I'm trying to use 4x4 button pad, so the array is the layout of the keypad. It's a button matrix, if that changes anything?)
The code is far from complete, but this is an error I need to iron out before I can continue.

I'm only going to post the section of the code that's giving me troubles,

Code: [Select]

int keyPad[4][4] =
{
  {1,2,3,10},
  {4,5,6,11},
  {7,8,9,12},
  {14,0,15,13}
};

void setup(){}
void loop()
{
  switch(keyPad){
//i have a lot of cases here, obviously
     }
}


When I try to verify the code, it says "error: switch quantity not an integer" which confuses me because every number in the ray, obviously, is an integer.
Thanks in advance

PaulS

Quote
When I try to verify the code, it says "error: switch quantity not an integer" which confuses me because every number in the ray, obviously, is an integer.

It doesn't make sense to try to switch on a multi-dimensioned array. Clearly (or so it seems), you want to switch on the value read from the keypad, not on the array itself.

Benry

Thanks Paul, I'll retry using the method on the Arduino Playground. Glad I wasn't too far into the project yet  ;)

Go Up