   delayMicroseconds(10);
   digitalWrite(Trig_pin, LOW);
 
-  delay(300);
+  delay(500);
 
-  if ( echoBufferx[1] > echoBufferx[0]   ) {
-    distancex = ( echoBufferx[1] - echoBufferx[0] ) / 29 / 2 ;
+  if ( echoBuffer[1] > echoBuffer[0]   ) {
+    distance = ( echoBuffer[1] - echoBuffer[0] ) / 29 / 2 ;
   } else {
-    distancex = 1000 ;
-  }
-
-  if ( echoBuffery[1] > echoBuffery[0]  ) {
-     distancey = ( echoBuffery[1] - echoBuffery[0] ) / 29 / 2 ;
-  } else {
-    distancey = 1000;
+    distance = 1000 ;
   }
 
   detachInterrupt(0);
-  detachInterrupt(1);
 
-  if ( distancex >= distancey ) {
-    return distancey;
-  } else {
-    return distancex;
-  }
-
+  return distance;
+  
 }
 
 void loop() {

#include <Average.h>

#define Trig_pin 4

volatile unsigned long echoBufferx[2];
volatile unsigned long echoBuffery[2];

volatile unsigned int x = 0;
volatile unsigned int y = 0;

Average<float> ave(5);


  Serial.begin (38400);
  pinMode(Trig_pin, OUTPUT);
  pinMode(2, INPUT_PULLUP);
}

long check_distance() {

  x = 0 ;

  int distance = 0;

  for ( int i = 0 ; i < 2 ; i++ ) {
    echoBuffer[i] = 0;
  }

  attachInterrupt(0, echo_Interrupt_Handler, CHANGE);

  delay(200);

