Keypad

Hi everyone, i need help to switch from 3 keymaps. What i have now is switching from 2 keymaps. How will i do this? Thank you very much!

char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};

char datakeys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'Z','0','Y','D'}
};

char* keypadMap = (alpha == true) ? makeKeymap(datakeys) : makeKeymap(keys);

default is keys and i use this “keypad.begin(*datakeys);” to switch to datakeys…

help is greatly appreciated. :slight_smile:

kengwapo: Hi everyone, i need help to switch from 3 keymaps. What i have now is switching from 2 keymaps. How will i do this? Thank you very much!

char* keypadMap = (alpha == true) ? makeKeymap(datakeys) : makeKeymap(keys);

default is keys and i use this "keypad.begin(*datakeys);" to switch to datakeys..

Same problem as 2 keymaps

make a byte variable set it to 0, 1, or 2 use a switch() or if statements to make the choice. or, put the addresses of the keymaps in an array.

Hi sir, can you give me example code? I don't know how to construct, to make it really work. Thank you sir :)

OK.. here's just one way.

byte keymapchoice = 0;
char* keypadmap;

  switch (keymapchoice) {
    case 0:
      keypadmap = makeKeymap(keys);
      break;
    case 1:
      keypadmap = makeKeymap(datakeys)
      break;
    case 2:
      keypadmap = makeKeymap(someNameKeys);
      break;
  }

You can also do it with multiple if statements. If you don't know how to do if statements, you REALLY need to do some research into the C or C++ language. See http://www.learncpp.com/

When does it changes case?

kengwapo: When does it changes case?

Whenever the value in keymapchoice changes, or in other words, whenever you change the value in keymapchoice.

The switch() takes the place of the line

char* keypadMap = (alpha == true) ? makeKeymap(datakeys) : makeKeymap(keys);

You don't really understand any of this, do you? If you want to write code, you'll have to do some learning. See the link in my other post, or check out the tutorials section. Load and run some of the examples that came with the Arduino software. Look at the code. Figure out what each statement does. Make changes and see what happens.

Sir, thank you so much. i made it work..

   switch (keymapchoice) {
    case 0:
      keypadmap = makeKeymap(keys);
      keypad.begin(*keys);
      break;
    case 1:
      keypadmap = makeKeymap(datakeys);
      keypad.begin(*datakeys);
      break;
    case 2:
      keypadmap = makeKeymap(datakeys2);
      keypad.begin(*datakeys2);
      break;
  }

God bless you :)