attach interrupt only once
attach interrupt only once

--- a/UltrasonicSensor/UltrasonicSensor.ino
+++ b/UltrasonicSensor/UltrasonicSensor.ino
@@ -43,9 +43,11 @@
   Serial.begin(9600);
 
   pinMode(SIGNAL_PIN, OUTPUT);
-  digitalWrite(SIGNAL_PIN, LOW); 
+  digitalWrite(SIGNAL_PIN, LOW);
 
   UltrasonicInterrupt::setup(pingPulseComplete, INTERRUPT_PIN);
+  // start listening out for the echo pulse on interrupt 0
+  UltrasonicInterrupt::begin();  
 }
 
 
@@ -75,9 +77,6 @@
   digitalWrite(SIGNAL_PIN, HIGH);
   delayMicroseconds(10); // I think I can cope with blocking for a whole 10us here...
   digitalWrite(SIGNAL_PIN, LOW);
-  
-  // start listening out for the echo pulse on interrupt 0
-  UltrasonicInterrupt::begin();
 }
 
 

--- a/UltrasonicSensor/libraries/UltrasonicInterrupt/UltrasonicInterrupt.cpp
+++ b/UltrasonicSensor/libraries/UltrasonicInterrupt/UltrasonicInterrupt.cpp
@@ -27,7 +27,7 @@
 void UltrasonicInterrupt::begin(){
 	state		= false;
 	active 		= true;
-	attachInterrupt(interrupt, pinChange, RISING);
+	attachInterrupt(interrupt, pinChange, HIGH);
 }
 
 
@@ -57,16 +57,9 @@
 	if(state){
 		// interrupt pin has changed, a pulse has started
 		pulseStart = micros(); // store the current microseconds
-		attachInterrupt(interrupt, pinChange, FALLING); // now wait for the falling edge
 	} else {
-
-		// pulse complete, detach the interrupt...
-		detachInterrupt(interrupt);
-
 		// pin state changed again - pulse ended
 		unsigned long duration = micros() - pulseStart; // get the pulse length
-
-		active = false;
 		onComplete(duration);
 	}
 }

comments