For use in my acoustic touchscreen project, found here: http://hackaday.io/project/1990-Low-Cost-Touchscreen-Anywhere

Dependencies:   mbed

Revision:
0:d678323f9a72
Child:
1:62933cace87a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Jul 26 16:58:52 2014 +0000
@@ -0,0 +1,82 @@
+#include "mbed.h"
+
+DigitalOut myled(dp1);
+DigitalOut led2(dp4);
+InterruptIn int1(dp14);
+InterruptIn int2(dp13);
+Timer t;
+Timeout reset;
+bool first = true;
+bool timeAvailable = false;
+
+void reset1();
+void reset2();
+
+float timeArray[3];  //important. this stores the delays between vibration detections
+                   //right now only indices 0 and 1 are used
+void flip1(){
+    if(first){
+        t.start();
+        int1.fall(NULL);
+        first = false;
+        reset.attach(&reset1,0.01);
+    }else{
+        t.stop();
+        timeArray[0]=t.read();
+        reset.detach();
+        timeAvailable=true;
+        first = true;
+    }
+    myled = 1;
+}
+
+void flip2(){
+    if(first){
+        t.start();
+        int2.fall(NULL);
+        first = false;
+        reset.attach(&reset2,0.01);
+    }else{
+        t.stop();
+        timeArray[1]=t.read();
+        reset.detach();
+        timeAvailable=true;
+        first = true;
+    }
+    led2 = 1;
+}
+
+void reset1(){
+    t.stop();
+    t.reset();
+    first = true;
+    int1.fall(&flip1);
+}
+
+void reset2(){
+    t.stop();
+    t.reset();
+    first = true;
+    int2.fall(&flip2);
+}
+
+int main() {
+    int1.fall(&flip1);
+    int2.fall(&flip2);
+    timeArray[0] = 0;
+    timeArray[1] = 0;
+    timeArray[2] = 0;   //for now this isn't used (only two sensors)
+    while(1){
+        if(timeAvailable){
+            printf("[%f, %f]\n",timeArray[0],timeArray[1]);
+            t.reset();
+            timeArray[0] = 0;
+            timeArray[1] = 0;
+            timeArray[2] = 0;   //for now this isn't used (only two sensors)
+            timeAvailable=false;
+            wait(.1);
+            int1.fall(&flip1);
+            int2.fall(&flip2);
+        }
+    }
+}