How can i combine this two code together? please help

Code 1:

#include <Servo.h>

int knockSensor = 0;
int pos = 0;
int ledPin =12;
int HIGHTHRESHOLD = 100;

Servo myservo;

void setup()
{
Serial.begin (9600);
myservo.attach(9);
pinMode (ledPin, OUTPUT);
}
void loop() {
int value = analogRead(knockSensor);
{
if (value==1)
for(pos = 55; pos <= 180; pos += 1)
{
myservo.write(55);
delay(10);
}
if (value==1)
for(pos = 180; pos >= 55; pos -= 1)
{
myservo.write(175);
delay(10);
}
if (value>HIGHTHRESHOLD)
for(pos = 55; pos <= 180; pos += 1)
{
myservo.write(55);
delay(1);
digitalWrite(ledPin, HIGH);
delay(1);
digitalWrite (ledPin,LOW);
delay(1);
}
if (value>HIGHTHRESHOLD)
for(pos = 180; pos >= 55; pos -= 1)
{
myservo.write(175);
delay(1);
digitalWrite (ledPin,HIGH);
delay (1);
digitalWrite (ledPin,LOW);
delay(1);
}
}
}

Code 2:

#include<Servo.h>
int pos = 0;

Servo servo;
void setup() {
pinMode(2, INPUT);
servo.attach(9);
}
void loop() {
if (digitalRead(2) == HIGH)
for(pos = 55; pos <= 180; pos += 1)
{
servo.write(55);
delay(10);
}
if (digitalRead(2) == HIGH)
for(pos = 180; pos >= 55; pos -= 1)
{
servo.write(175);
delay(10);
}
}

make every varaiable unique so variables in sketch 1 do have different names than in sketch 2

merge the global variables

merge the content of the setup call

merge the content of the loop call

resolve remaining conflicts

done

Follow Rob’s advice about merging but what do you want the merged code to do ?

What does this do, for instance

for(pos = 55; pos <= 180; pos += 1)
  {
    myservo.write(55);
    delay(1);
    digitalWrite(ledPin, HIGH);
    delay(1); 
    digitalWrite (ledPin,LOW);
    delay(1);  
  }

At best it moves the servo to the same position 125 times and makes an LED glow dimly for a fraction of a second. Is that what it is meant to do ?

This Simple Merge Demo may give you some ideas.

...R