Pages: [1]   Go Down
Author Topic: Switch() case using arrays  (Read 251 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks Paul, I'll retry using the method on the Arduino Playground. Glad I wasn't too far into the project yet  smiley-wink
Logged

Pages: [1]   Go Up
Jump to: