implementing two methods to control a servo

Hi I recently completed my Servo keypad project and I wanted to add a function where if you push a button it will unlock the door from the inside as I can not manually turn it. I have tried to implement this into my code but it will not work. Here is the code and I will highlight the area of concern. Please also note that the code works by itself, just not with the keypad code included in it. I posted the code I need to implement into the main project below the main code, because it would not let me change the color. Thank you for any help!

#include <Keypad.h>
#include <Servo.h>

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] = {8, 7, 6, 5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {4, 3, 2}; //connect to the column pinouts of the keypad

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

char inputArray[4]; //array to gather user keypad presses
char Main[4] = {'5','9','9','7'}; //array to hold keypad password
char Guest[4] = {'4','1','1','8'}; //array to allow guest to enter
char Lock[4] = {'1','1','1','1'}; //disables guest mode
char Unlock[4] = {'2','2','2','2'}; //enables guest mode

#define ledPin 13 //led to register keypad pressses
#define registerPin 12 //led that registers correct password entry

int i = 0;
int state = 1; //Creates the state

int inputPin = 10;      // Push button input pin
int btnVal = 0;         // Current value of pushbutton

Servo mrservo;  // create servo object to control the servo

void setup()
{
Serial.begin(9600); //open serial port
pinMode(ledPin, OUTPUT); //define led pin as output
pinMode(registerPin, OUTPUT); //define led pin as output

mrservo.attach(9);  //attaches servo to pin 9 on the servo object

pinMode(inputPin, INPUT); // Push Button


}

void loop()
{
  btnVal = digitalRead(inputPin);
  if(btnVal == HIGH) {
   mrservo.write(95); //Move the servo to 95 degrees
   delay(1000); //Wait 1 second
   mrservo.write(0); //Move the servo to 0 degrees
   delay(1000); //Wait 1 second
 }
{
 while (state = 1)

  {


  char key = kpd.getKey();

  //if a key is pressed
    if(key)
	{

	//turn on ledPin
	digitalWrite(ledPin, HIGH);
	delay(100);
	digitalWrite(ledPin, LOW);
	delay(100);
	inputArray[i] = key; //store entry into array
	i++;
	Serial.println(key); //print keypad character entry to serial port

	if (key=='*')
	  {
	    Serial.println("Reset");
	    i=0; //reset i
	  }

	if (i == 4) //if 4 presses have been made
	  {
	    {

	    //match input array to password array

		if (inputArray[0] == Main[0] &&
		inputArray[1] == Main[1] &&
		inputArray[2] == Main[2] &&
		inputArray[3] == Main[3])
		   {
		    digitalWrite(registerPin, HIGH); //turn on registerPin led
		    delay(2000);
		    digitalWrite(registerPin, LOW);
                    mrservo.write(75);
                    delay(15000); 
                    mrservo.write(30); 
                    delay(500);
		   }
	    }

	    {

	    //match input array to password array

		if (inputArray[0] == Guest[0] &&
		inputArray[1] == Guest[1] &&
		inputArray[2] == Guest[2] &&
		inputArray[3] == Guest[3])
		   {
                    // moves servo after correct code entered.
                    digitalWrite(registerPin, HIGH); //turn on registerPin led
		    delay(2000);
		    digitalWrite(registerPin, LOW);
		    mrservo.write(75);
                    delay(15000); 
                    mrservo.write(30); 
                    delay(500);
                
		   }
	    }

	    {

	    //match input array to password array

		if (inputArray[0] == Lock[0] &&
		inputArray[1] == Lock[1] &&
		inputArray[2] == Lock[2] &&
		inputArray[3] == Lock[3])
		   {
                    digitalWrite(registerPin, HIGH); //turn on registerPin led
		    delay(2000);
		    digitalWrite(registerPin, LOW);
		    Serial.println("State 2");
		    state = 2;
		    break;
		   }
	    }

	    {
	    i=0; //reset i
	    }
	  }
	}
    };
   }

 {

  while (state = 2)

  {


  char key = kpd.getKey();

  //if a key is pressed
    if(key)
	{

	//turn on ledPin
	digitalWrite(ledPin, HIGH);
	delay(100);
	digitalWrite(ledPin, LOW);
	delay(100);
	inputArray[i] = key; //store entry into array
	i++;
	Serial.println(key); //print keypad character entry to serial port

	if (key=='*')
	  {
	    Serial.println("Reset");
	    i=0; //reset i
	  }

	if (i == 4) //if 4 presses have been made
	  {
	    {

	    //match input array to password array

		if (inputArray[0] == Main[0] &&
		inputArray[1] == Main[1] &&
		inputArray[2] == Main[2] &&
		inputArray[3] == Main[3])
		   {
		    digitalWrite(registerPin, HIGH); //turn on registerPin led
		    delay(2000);
		    digitalWrite(registerPin, LOW);
                    mrservo.write(75);
                    delay(15000); 
                    mrservo.write(30); 
                    delay(500);
		   }
	    }

	    {

	    //match input array to password array

		if (inputArray[0] == Unlock[0] &&
		inputArray[1] == Unlock[1] &&
		inputArray[2] == Unlock[2] &&
		inputArray[3] == Unlock[3])
		   {
		    Serial.println("State 1");
		    state = 1;
		    break;
                    digitalWrite(registerPin, HIGH); //turn on registerPin led
		    delay(2000);
		    digitalWrite(registerPin, LOW);
		   }
	    }

	    {
	    i=0; //reset i
	    }
	  }
	}
    };
}
}

This is the code I need to implement, above I have tried but it will not work.

#include <Servo.h>

int inputPin = 10;
int btnVal = 0;

Servo mrservo;

void setup()
{
  pinMode(inputPin, INPUT);
  mrservo.attach(9);
}

void loop()
{
  btnVal = digitalRead(inputPin);
  if(btnVal == HIGH) {
   mrservo.write(95); //Move the servo to 95 degrees
   delay(1000); //Wait 1 second
   mrservo.write(0); //Move the servo to 0 degrees
   delay(1000); //Wait 1 second
 }
}

How about if you modify your keypad array (and I/O) to integrate your inside/manual button as a key?

  {'1','2','3',x},
  {'4','5','6',x},
  {'7','8','9',x},
  {'*','0','#',!}

x = not used
! = inside button/key

runaway_pancake:
How about if you modify your keypad array (and I/O) to integrate your inside/manual button as a key?

  {'1','2','3',x},

{'4','5','6',x},
  {'7','8','9',x},
  {'*','0','#',!}

x = not used
! = inside button/key

This would work assuming I had a 4X4 keypad, and i need the button to be on the inside of the door so I can open it from the inside.

the button doesn't have to be physically in that spot, its just nicer to look at, nor a button in the rest of the column, just easier to program
its how you wire it that makes it work

winner10920:
the button doesn't have to be physically in that spot, its just nicer to look at, nor a button in the rest of the column, just easier to program
its how you wire it that makes it work

No, I need the keypad on the outside of the door, to open from the outside, but on the inside of the door I need a push button so I can open it from the inside to let others in without telling them the code.

This would work assuming I had a 4X4 keypad, and i need the button to be on the inside of the door so I can open it from the inside.

You don't need a 4x4 - just add the inside button wired as though it was in the 4th column, 4th row of a 4x4.
You would have to modify your array to account for a fourth column input (it already has a 4th row) and the decode accordingly.
Doesn't that make sense?

Here's a pic of how to do it.
There's an example of decoding a 4x4 in the keypad tutorial in Playground

3x4+1.JPG

runaway_pancake:
Here's a pic of how to do it.
There's an example of decoding a 4x4 in the keypad tutorial in Playground

Ahh I see what you are saying, it will take longer but this should work better. Thank you for your help!

Why do you need to have it as part of the matrix? It doesn't save you any pins since you aren't using the rest of the column, just have one part of the pb switch to ground, the other to an arduino pin and enable a pullup on that pin, then check if it goes low and open the door, its still two wires except they can go to the arduino not the matrix, maybe that'll be easier to wire and can be done separate of the keypad process

"Why do you need to have it as part of the matrix?"

This just keeps the extra switch as part of the keypad framework.