Adding code together

Hello all, does anyone have any advice in adding two pieces of code together? Im very new to coding, and Im working on a school project. The 2 pieces of code work separately, but I need to implement them together to make a project work. I have a one-wire input 4x4 keypad that I am trying to use as a security code to turn a servo to open a door.

Here is that code:

String keys="123A456B789C*0#D";
int key;
boolean key_lockout=false;

void setup(){
   Serial.begin(9600); 
}

void loop(){
  key=getKeypad();
  if(key!=-1)
      Serial.println(keys[key]);
   delay(10);
}

int getKeypad(){
  int ret=-1;
  boolean reset_lockout=false;
  if(analogRead(A0)==0)
    key_lockout=false;
  else if(!key_lockout){
    delay(20);
    ret=15-(log((analogRead(A0)-183.9)/58.24)/0.1623)+0.5;
    key_lockout=true;
  }
  return ret;
}

Then, I have a bush-button release code to operate the door from the inside, that code is:

#include <Servo.h>
int button1 = 4; //button pin, connect to ground to move servo
int press1 = 0;
int pos = 90;
Servo servo1;

void setup()
{
  pinMode(button1, INPUT);
  servo1.attach(13);
  digitalWrite(4, HIGH); //enable pullups to make pin high
}

void loop()
{
  press1 = digitalRead(button1);
  if (press1 == LOW)
  {
    servo1.write(0);
    delay(5000);
    servo1.write(90);
  }
}

Any advice? I know I need to add a "password detect" piece of coded, but I am not sure how. Any advice would be awesome. Thank you.

See:
http://www.thebox.myzen.co.uk/Tutorial/Merging_Code.html

LarryD:
See:
http://www.thebox.myzen.co.uk/Tutorial/Merging_Code.html

Thank you, that has slightly helped, but I just can't figure it out. It seems so simple, yet I am having trouble. I tried to even just take the "setup" and "loop" parts and combine them, definitely a no-go. Any advice?

Any advice?

Post your code.

This demo shows how to merge two Arduino programs - it may give you some ideas.

Try it and if it does not work post the code that you have created.

...R

Edited to correct broken link

You need to explain what it means to be "having trouble".... does it compile but not run as you hoped- if so explain what's not working. If it doesn't compile, you need to post the compile errors.

(And post your code, of course....)

@Robin2
Your link does not work.

LarryD:
@Robin2
Your link does not work.

Sorry, and thanks for pointing it out. It's fixed now.
I was foolishly relying on the "new" Forum system's wysiwyg editor - which I normally avoid.

...R