Pushbutton Combination lock

So I’m trying to make a combination lock project that I found online. Here:

I’m only doing the version that uses the pushbuttons and not the OSC controlled version except I’m using six pushbuttons instead of four and I have a seventh button acting as a reprogramming button to change the combo with. While holding the reprogram button the user can enter their own combo. Here’s a link to the code found at the bottom of the tutorial:
http://www.instructables.com/files/orig/FJH/5J36/GPBD3L1V/FJH5J36GPBD3L1V.tmp
Problem:
The program requires the reset button on the arduino board to be pushed upon successful entry of the combo which resets my arrays, making the board “forget” the combo that the user has inputted. This means that upon every reset the user must hold the reprogram button, enter their own combo and then enter it again to “unlock” the lock. I’d like it instead to “remember” the combo that the user gave it regardless of whether they’ve unlocked the lock.

int pb1 = 31;
int pb2 = 32;
int pb3 = 33;
int pb4 = 34;
int pb5 = 35;
int pb6 = 36;       //6 pushbuttons for keypad
int pbreset = 37;       //1 pushbutton for reset
int ledg = 40;      //green led forsuccessful unlock
int ledr = 41;       //red led for failed unlock
int buzz = 44;      //buzzer for successful unlock or failed unlock

int combo[6] /*= {1,2,3,4,5,6}*/;  //6-digit combination
int entered[6];               //combo that the user enters 

void setup()  {
  Serial.begin(9600);
  
  pinMode (pb1, INPUT);
  pinMode (pb2, INPUT);
  pinMode (pb3, INPUT);
  pinMode (pb4, INPUT);
  pinMode (pb5, INPUT);
  pinMode (pb6, INPUT);
  pinMode (pbreset, INPUT);    //all buttons are inputs
  pinMode (ledg, OUTPUT);
  pinMode (ledr, OUTPUT);
  pinMode (buzz, OUTPUT);  //buzzer and led's are outputs
  
  for (int i = 0; i < 6;i++)  {   //display values in the combo and entered array - all zeros as of this point
    Serial.println(combo[i]); 
    Serial.println(entered[i]);
  }
  
  resetbutton();                //just afunction that blinks the leds so I know the board has restarted
  resetbutton();
  //digitalWrite(ledr, HIGH);
}

void loop()  {
  
  reprogram();                        //function used to change the combination (fill the combo array)
   
  if (digitalRead(pb1) == HIGH)   {
    checkElement1(1);
    delay(250);
  }
  else if (digitalRead(pb2) == HIGH)  {
    checkElement1(2);
    delay(250);
  }
  else if (digitalRead(pb3) == HIGH)  {
    checkElement1(3);
    delay(250);
  }
  else if (digitalRead(pb4) == HIGH)  {
    checkElement1(4);
    delay(250);
  }
  else if (digitalRead(pb5) == HIGH)  {
    checkElement1(5);
    delay(250);
  }
  else if (digitalRead(pb6) == HIGH)  {
    checkElement1(6);
    delay(250);
  }
                                        //if one of the "keyppad" buttons is pushed then it will pass its assigned number to checkElement1 
}

void checkElement1(int button)  {
 if (entered[0] != 0)   {               //first element in the entered array has a value other than zero meaning it has been assigned a button
   checkElement2(button);               //move to checkentered 2, passing it "button"
 }
 else if (entered[0] == 0)  {           //the element in the entered array has not been assigned a value by a button press 
  entered[0] = button;                  //give this element the the "button" value
  Serial.print("1: ");Serial.println(entered[0]);  //display "1: " indicatingit is the first pressed and then the value in the current "ntered" element
 }
}

void checkElement2(int button)  {
 if (entered[1] != 0)  {
  checkElement3(button);
 } 
 else if (entered[1] == 0)  {
   entered[1] = button;
   Serial.print("2: ");Serial.println(entered[1]);
 }
 
}

void checkElement3(int button)  {
 if (entered[2] != 0)  {
  checkElement4(button);
 } 
 else if (entered[2] == 0)  {
  entered[2] = button;
  Serial.print("3: ");Serial.println(entered[2]);
 }
 
}

void checkElement4(int button)  {
 if (entered[3] != 0)  {
  checkElement5(button);
 }
 else if (entered[3] == 0)  {
   entered[3] = button;
   Serial.print("4: ");Serial.println(entered[3]);
 }
}

void checkElement5(int button)  {
  if (entered[4] != 0)  {
    checkElement6(button);
  }
  else if (entered[4] ==0)  {
    entered[4] = button;
    Serial.print("5: ");Serial.println(entered[4]);
  }
}

void checkElement6(int button)  {
  if (entered[5] == 0)  {
    entered[5] = button;
    
    Serial.print("6: ");Serial.println(entered[5]);
    
    delay(100);
    compareCombo();
  }
}

void compareCombo()  {
 if ((combo[0] == entered[0]) && (combo[1] == entered[1]) && (combo[2] == entered[2]) && (combo[3] == entered[3]) && (combo[4] == entered[4]) && (combo[5] == entered[5]))  {
   for (int i = 0; i<6; i++)  {    //if each element in the combo and corresponding entered array match 
   Serial.println(entered[i]);     //print the values that have been entered
   }
  
   digitalWrite(ledg, HIGH);      //unlock output (turn on green led)
 }
 else /*if ((combo[0] != entered[0]) || (combo[1] != entered[1]) || (combo[2] != entered[2]) || (combo[3] != entered[3]) || (combo[4] != entered[4]) || (combo[5] != entered[5]))*/  {
   digitalWrite(ledr, HIGH);      //failed entry output 
   for (int i = 0; i<6; i++)  {
    entered[i] = 0; 
    Serial.println(entered[i]);
   }
 }
}

void resetbutton()  {            //blinks both leds
  digitalWrite(ledr, HIGH);
  digitalWrite(ledg, HIGH);
  delay(100);
  digitalWrite(ledr, LOW);
  digitalWrite(ledg, LOW);
  delay(100);
}

  
  void reprogram()  {
    while (digitalRead(pbreset) == HIGH)  {  //loop as long as reprogram button is pressed
    Serial.print("pbreset");
    int i = 0;
     while (i < 6)  {                        //fills each element in the combo array until all six are filled
       if (digitalRead(pb1) == HIGH)  {
        combo[i] = 1;
        i++;
        delay(250);
       }
       else if (digitalRead(pb2) == HIGH)  {
         combo[i] = 2;
         i++;
         delay(250);
       }
       else if (digitalRead(pb3) == HIGH)  {
         combo[i] = 3;
         i++;
         delay(250);
       }
       else if (digitalRead(pb4) == HIGH)  {
         combo[i] = 4;
         i++;
         delay(250);
       }
       else if (digitalRead(pb5) == HIGH)  {
         combo[i] = 5;
         i++;
         delay(250);
       }
       else if (digitalRead(pb6) == HIGH)  {
         combo[i] = 6;
         i++;
         delay(250);
       }
     }
   }
  }

Serial Monitor:
Will display 12 zero’s. Six for the combo array then six for the entered array
If the user goes straight to pushing one of the six “keypad” buttons it will display “1: (buttton entered)”, "2: (button entered) etc.
After six buttons have been pushed, it will print the 6 values for the entered array again, all zero’s if the combination entered is wrong or the correct values that correspond with the buttons entered if the lock “unlocks”. (i’m not sure why this is)

Thanks for reading.

20140417_145235[1].jpg

Did you ever figure this out? I'm wanting to do the same thing.

I too want to do this project but only the original one with the 4 buttons but the code doesn't work anymore, something to do with the BYTE part I think. The errors are:

Arduino: 1.8.1 (Linux), Board: "Arduino/Genuino Uno" /home/paul/Arduino/keypad_project/keypad_project.ino: In function 'void loop()': keypad_project:54: error: 'checkEntered1' was not declared in this scope checkEntered1(1); //call checkEntered and pass it a 1 ^ keypad_project:59: error: 'checkEntered1' was not declared in this scope checkEntered1(2); //call checkEntered1 and pass it a 2 ^ keypad_project:63: error: 'checkEntered1' was not declared in this scope checkEntered1(3); //call checkEntered1 and pass it a 3 ^ keypad_project:67: error: 'checkEntered1' was not declared in this scope checkEntered1(4); //call checkEntered1 and pass it a 4 ^ /home/paul/Arduino/keypad_project/keypad_project.ino: In function 'void compareCode()': keypad_project:120: error: expected ';' before 'ln' Serial.write ln(entered*, BYTE);* ^ keypad_project:120: error: statement cannot resolve address of overloaded function Serial.write ln(entered*, BYTE);* ^ exit status 1 'checkEntered1' was not declared in this scope Thought since you have done the project that you would know how to fix the original.