But that’s a question. I haven’t answered myself.
I can’t figure out how to do it. I’ve read about matrixes and how they work, but I don’t know how to make the swap.
Using the basic keypad tutorial in a 4x3 matrix and the toggle connected to pin 9, how do I make an “if…else” statement to make this
#include <Keypad.h>
int togglePin = 9; // //// this would be the toggle SW
int state = HIGH;
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'#','0','*'}
};
byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {8, 7, 6}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
Serial.begin(9600);
}
void loop(){
char key = keypad.getKey();
if (key != NO_KEY){
Serial.println(key);
}
into this
const byte ROWS2 = 4; //four rows
const byte COLS2 = 3; //three columns
char keys2[ROWS2][COLS2] = {
{'r','t','y'},
{'q','w','e'},
{'a','s','d'},
{'z','x','c'}
};
byte rowPins[ROWS2] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte colPins[COLS2] = {8, 7, 6}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys2), rowPins, colPins, ROWS2, COLS2 );
void setup(){
Serial.begin(9600);
}
To my understanding, it’s something like
void setup()
{
pinMode(togglePin, INPUT);
}
void loop()
{
reading = digitalRead(togglePin);
{
if (state == HIGH) // ////use Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
else // //// use Keypad( makeKeymap(keys2), rowPins, colPins, ROWS2, COLS2 );
}
But how?
Edit: orthography correction