Comparing a string with a multidimensional matrix

I’m studying to implement a keypad password which should take 2 different actions according the inputted password.
For example one password is used for the gate and one is for the door.
Here’s the code

#include <Keypad.h> 

#define LED 11    
const byte ROWS = 4; 
const byte COLS = 3; 
byte i; 
byte j; 
byte s; 
char keybuffer[4];
// Secret codes
char code[2][4]= {
char keys[ROWS][COLS] = { 
byte rowPins[ROWS] = {8,7,6,5};
byte colPins[COLS] = {4,3,2};

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); 

void setup() 
  pinMode(LED + 1,OUTPUT); 
  pinMode(LED + 2,OUTPUT); 

void keypadEvent(KeypadEvent eKey){
  switch (keypad.getState())
    case PRESSED:
 Serial.print(" ");
 switch (eKey)
  case '*': j = 0;
      Serial.println("Password reset");
  case '#': 
      checkPW(); break;
      keybuffer[j] = eKey;
      if (j < 5) ++j;
void checkPW(void) 
  i = 0;
  while (i < 3)
    s = 0; 
    for (j = 0;j <5; j++)
        if (keybuffer[j] == code[i][j]) ++s;
    if (s > 3)
    else i += 1;

void loop() 
  Serial.println("Input PIN");
  i = 0;
  while (i == 0)
  Serial.print("i = ");

What is happening is that the passwords are recognized but I can’t get the index of which is pointing, the variable i remains always zero.
I’m very new in programming in C, so what could be my mistake ?
I know the programming logics, but not much (I wrote something with Python). For example I could use the password library, but it would take 2 instances and I don’t know how to pass the passwords objects into a while loop.


I briefly looked at your code … I do just fine with single dimensions but multi-dimensional arrays hurt my head (I used to program in Fortran and swore-off multidimensional arrays 30 years ago!)

Usually what I do is a bit ugly, but I brute-force it… say, I am looking for GPRMC as the beginning of an input string from a GPS, then I will first look for "" and knowing this is the start character, I’ll load the remaining characters into an array until I get a CR or LF. Then I match [3], [4], [5] for “R” & “M” & “C”. If I get a match, I continue to extract time and date or I just start over with my index at 0 until I get ‘$’

So, it looks like this in the test:

   if ( (GPSbuffer[3] == 0x52) && (GPSbuffer[4] == 0x4d) && (GPSbuffer[5] == 0x43)) // 'R' && 'M' && 'C'

I included the entire code as an attachment but you really should not need it.

Good luck,


TardisTimeMulticast.ino (6.85 KB)

Sorry, but I don't find a tight relationship with my case.
I have, as you could see, a multidimensional array and I attempt to know which are the pointer after the match is true.
So for the j index is fine, but when comes to look for the x it isn't possible and always returns zero. ??? ???
A second attempt might use the power of C++. As I suppose (like Python) to pass a password object to the function. But I think it's a bit of complication, for this case.