Hello, sorry for my bad English, but it is not my native language and I do not speak it well.
I come to the forum because I need help, I can't get a matrix keyboard to work (8 columns x 2 rows, in the future it will be 16 columns and 3 rows) in conjunction with a CD74HC4067 multiplexer.
I am using the CD74HC4067 with the following distribution to Arduino Pro Micro:
next = 5
s3 = 9
s2 = 8
s1 = 7
s0 = 6
in = gnd
vdc = 5v
gnd = gnd
the matrix keyboard has the columns connected to 8 pins from c15 to c8 (on the multiplexer) and the 2 rows are connected to pins 15 and 14 directly on the arduino pro micro.
the keyboard matrix works perfectly connected directly to the arduino, but when trying to modify the code to use it with the already mentioned distribution, I couldn't do it, logically because there is some error in the logic that I am applying to elaborate the code.
please if someone can help me or give me an idea to use the multiplexer as matrix keyboard columns.
Now I leave the code that I have not been able to carry out correctly.
#include <Keypad.h>
const int muxSIG = 5;
const int muxS0 = 6;
const int muxS1 = 7;
const int muxS2 = 8;
const int muxS3 = 9;
int SetMuxChannel(byte channel){
digitalWrite(muxS0, bitRead(channel, 0));
digitalWrite(muxS1, bitRead(channel, 1));
digitalWrite(muxS2, bitRead(channel, 2));
digitalWrite(muxS3, bitRead(channel, 3));
}
byte c8 = SetMuxChannel(8);
byte c9 = SetMuxChannel(9);
byte c10 = SetMuxChannel(10);
byte c11 = SetMuxChannel(11);
byte c12 = SetMuxChannel(12);
byte c13 = SetMuxChannel(13);
byte c14 = SetMuxChannel(14);
byte c15 = SetMuxChannel(15);
//uint8_t c15 = SetMuxChannel(15);
const byte ROWS = 2; // rows
const byte COLS = 8; // columns
byte rowPins[ROWS] = {15,14}; //connect to the row pinouts of the kpd
byte colPins[COLS] = {c8,c9,c10,c11,c12,c13,c14,c15}; //connect to the column pinouts of the kpd
byte keys[ROWS][COLS] = {
{1,2,3,4,5,6,7,8},
{9,10,11,12,13,14,15,16}
};
Keypad kpdA = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
String msg;
int data;
void setup() {
Serial.begin(115200);
pinMode(muxS0, OUTPUT);
pinMode(muxS1, OUTPUT);
pinMode(muxS2, OUTPUT);
pinMode(muxS3, OUTPUT);
//pinMode(muxSIG, INPUT_PULLUP);
msg = "";
}
void loop() {
// Fills kpd.key[ ] array with up-to 10 active keys.
// Returns true if there are ANY active keys.
if (kpdA.getKeys())
{
for (int i=0; i<LIST_MAX; i++) // Scan the whole key list.
{
if ( kpdA.key[i].stateChanged ) // Only find keys that have changed state.
{
if ( (kpdA.key[i].kstate) == PRESSED) { // Report active key state : IDLE, PRESSED, HOLD, or RELEASED
data = byte(kpdA.key[i].kchar);
msg = " PRESSED.";
Serial.print("Key ");
Serial.print(data);
Serial.println(msg);
}
if ( (kpdA.key[i].kstate) == RELEASED) {
data = byte(kpdA.key[i].kchar);
msg = " RELEASED.";
Serial.print("Key ");
Serial.print(data);
Serial.println(msg);
}
}
}
}
} // End loop
