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(){

void loop(){

int getKeypad(){
  int ret=-1;
  boolean reset_lockout=false;
  else if(!key_lockout){
  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);
  digitalWrite(4, HIGH); //enable pullups to make pin high

void loop()
  press1 = digitalRead(button1);
  if (press1 == LOW)

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.


LarryD: See:

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.


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.