How to combine a code.

I'm a newbie here, i got an problem combine the coding. i got a servo motor with button coding and want to combine with IR obstacle sensor with buzzer coding. the problem is, before the button pressed, the IR sensor and buzzer are working. But when the button pressed the IR sensor and buzzer is not working.

help me with this.

#include <Servo.h>

Servo myservo;

#define servoPin 9
#define buttonPin1 11
#define buttonPin2 12
#define buz 7
#define obstaclePin 1
int hasObstacle = HIGH;
unsigned long interval_10, interval_12;

void button1();
void button2();

void setup() {
myservo.attach(servoPin);
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
pinMode(buz, OUTPUT);
pinMode(obstaclePin, INPUT);
digitalWrite(buttonPin1, HIGH);
digitalWrite(buttonPin2, HIGH);
interval_10 = 6000;
interval_12 = 12000;
myservo.write(180);
myservo.detach();
}

void loop() {
if(digitalRead(buttonPin1) == LOW)
{
digitalWrite(buttonPin1, LOW);
button1();
delay(interval_10);
loop;
}
if(digitalRead(buttonPin2) == LOW)
{
digitalWrite(buttonPin2, LOW);
button2();
delay(interval_12);
loop;
}

hasObstacle = digitalRead(obstaclePin);
if (hasObstacle == HIGH)
{
digitalWrite(buz, HIGH);
}
if (hasObstacle == LOW)
{
digitalWrite(buz, LOW);
}
delay(200);
loop;

}

void button1()
{
myservo.attach(servoPin);
myservo.write(0);
delay(500);
myservo.write(180);
delay(500);
myservo.write(0);
delay(500);
myservo.write(180);
delay(500);
myservo.detach();
}

void button2()
{
myservo.attach(servoPin);
myservo.write(0);
delay(500);
myservo.write(180);
delay(500);
myservo.write(0);
delay(500);
myservo.write(180);
delay(500);
myservo.detach();
}

  loop;

??

void button1()

WTF? This function has NOTHING to do with buttons. Or switches. You should NOT expect us to guess what your code is doing/supposed to do. Use names for functions that make it clear.

After all, the Arduino team did NOT develop a T2834t5() function to read a digital pin. They developed a function whose name CLEARLY indicates that it reads a digital pin.

Your function names should do no less.

PaulS:
After all, the Arduino team did NOT develop a T2834t5() function to read a digital pin. They developed a function whose name CLEARLY indicates that it reads a digital pin.....

..... just like analogWrite() writes a variable voltage between 0 and 5V?

kenwood120s:
..... just like analogWrite() writes a variable voltage between 0 and 5V?

As far as my LED is concerned, yes.

I will agree that that is without a doubt the worst named Arduino-provided function.