combine 2 codes on 1 arduino

Hi,

I got 2 codes and I want to combine it.
the first code are 4 leds who turns on and off.
the second code is a keypad who switch a relay.

int LED1 = 0;
int LED2 = 1;
int LED3 = 2;
int LED4 = 3;
void setup() {
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(LED4, OUTPUT);
}

void loop(){

void loop();

digitalWrite(LED1, HIGH);//300
  digitalWrite(LED2, HIGH);//300
    digitalWrite(LED3, HIGH);//300
      digitalWrite(LED4, HIGH);//800
  delay(300);//1=0 2=0 3=0 4=500
digitalWrite(LED1, LOW);
  digitalWrite(LED2, LOW);
    digitalWrite(LED3, LOW);
  delay(100);//1=300 2=300 3=800 4=400
digitalWrite(LED1, HIGH);
  digitalWrite(LED2, HIGH);
    digitalWrite(LED3, HIGH);
  delay(300);//1=0 2=0 3=500 4=100
digitalWrite(LED1, LOW);
  digitalWrite(LED2, LOW);
   delay(100); //1=300 2=300 3=400 4=0
digitalWrite(LED1, HIGH);
  digitalWrite(LED2, HIGH);    
      digitalWrite(LED4, LOW);
   delay(100); //1=200 2=200 3=300 4=800
      digitalWrite(LED4, HIGH);
         delay(200); //1=0 2=0 3=100 4=600
digitalWrite(LED1, LOW);
  digitalWrite(LED2, LOW);
    delay(100);//1=300 2=800 3=0 4=500
digitalWrite(LED1, HIGH);
  digitalWrite(LED2, HIGH);    
    digitalWrite(LED3, LOW);     
      delay(100); //1=200 2=700 3=800 4=400 
    digitalWrite(LED3, HIGH);     
          delay(200); //1=0 2=600 3=600 4=200
      digitalWrite(LED1, LOW);
delay(100); //1=800 2=500 3=500 4=100
digitalWrite(LED1, HIGH);
delay(100); //1=700 2=400 3=400 4=0
digitalWrite(LED4, LOW);
delay(100); //1=600 2=300 3=300 4=300
digitalWrite(LED4, HIGH);
delay(300); //1=600 2=0 3=0 4=300
digitalWrite(LED2, LOW);
digitalWrite(LED3, LOW);
digitalWrite(LED4, LOW);
delay(100); //1=500 2=800 3=800 4=0
digitalWrite(LED4, HIGH);
digitalWrite(LED2, HIGH);
digitalWrite(LED3, HIGH);
delay(200); //1=300 2=600 3=600 4=0
delay(100); //1=200 2=500 3=500 4=300
digitalWrite(LED4, LOW);
delay(200); //1=0 2=300 3=300 4=100
digitalWrite(LED4, HIGH);
digitalWrite(LED1, LOW);
delay(100); //1=0 2=200 3=200 4=0
delay(100); //1=0 2=100 3=100 4=300
delay(100); //1=0 2=0 3=0 4=200
digitalWrite(LED4, LOW);
digitalWrite(LED2, LOW);
digitalWrite(LED3, LOW);
delay(100); //1=0 2=0 3=800 4=100
digitalWrite(LED3, HIGH);
delay(100); //1=0 2=0 3=700 4=0
delay(700); //1=0 2=0 3=0 4=0
digitalWrite(LED3, LOW);
delay(3000);
}
#include <Keypad.h>
#include <Password.h>
#include <Servo.h>

Password password = Password( "4317" ); //password to unlock box, can be changed


const byte ROWS = 4; //4 rijen
const byte COLS = 3; //3 kolommen
char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'},

};
byte rowPins[ROWS] = {10 ,9, 8, 7}; //connect aan 4567
byte colPins[COLS] = {6, 5, 4}; //connect aan 8910
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );



void setup(){
  Serial.begin(9600);
  Serial.write(254);
  Serial.write(0x01);
  delay(200); 
  pinMode(A0, OUTPUT);  //green light
  pinMode(12, OUTPUT);  //red light
  pinMode(13, OUTPUT);  //relay
  keypad.addEventListener(keypadEvent); //add an event listener for this keypad
  
 }

void loop() {

 keypad.getKey();
  }
  //take care of some special events
  void keypadEvent(KeypadEvent eKey){
  switch (keypad.getState()){
  case PRESSED:
  
  Serial.print("Enter: ");
  Serial.println(eKey);
  digitalWrite(A0, HIGH);
  delay(10);
  digitalWrite(A0, LOW);
  
  
  Serial.write(254);
  
  switch (eKey){
    case '#': checkPassword(); delay(1); break;
    
  case '*': password.reset(); delay(1); break;
    
     default: password.append(eKey); delay(1);
}
}
}
void checkPassword(){
  
if (password.evaluate()){  //if password is right open box
    
    Serial.println("Accepted");
    Serial.write(254);delay(10);
    //Add code to run if it works
   
    
        digitalWrite(A0, HIGH);//turn LED on
         digitalWrite(13, HIGH);//turn RELAY on
    delay(5000); //wait 5 seconds
    digitalWrite(A0, LOW);// turn LED off
    digitalWrite(13, LOW);//turn relay off
    
    
}else{
    Serial.println("Denied"); //if passwords wrong keep box locked
    Serial.write(254);delay(10);
    //add code to run if it did not work
    
    digitalWrite(12, HIGH); //turn on
    delay(5000); //wait 5 seconds
    digitalWrite(12, LOW);//turn off

}}

can anyone help me?
thanks!

I'm not sure what the problem is, though I'm puzzled why you should include servo.h for the application you describe.

Perhaps you could expand?

Allan

Then there's using serial pins for LEDs,
the delays, the
crazy
pointless
indentation . . .

void loop(){

void loop();

Does that even compile? You can't put a forward declaration for a function inside the function itself.

What do you expect the resulting merged code to do? We can't read your mind or see the components in front of you.

The blinky-LED code is using a lot of delays. The first step in combining the codes would be to eliminate all the delays. Before doing that, you need to learn how to use millis() for timing. A good way of doing that would be to work out how to remove the delay from the second code.

google!

Mark